home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap11 / howto04 / cciccfrm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-12  |  192.3 KB  |  5,550 lines

  1. unit Cciccfrm;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, Menus, FileCtrl, CCWSock, CCICCInf,
  8.   CCICCPrf, IniFiles, Gauges , CCUUCode;
  9.  
  10. type
  11.   { This record holds the information for a number of internet connections }
  12.   PConnectionsRecord = ^TConnectionsRecord;
  13.   TConnectionsRecord = record
  14.     CProfile   : String; { Connection profile; used in lists }
  15.     CIPAddress : String; { Dotted character IP Address       }
  16.     CUserName  : String; { Login name to site; can be anonym }
  17.     CPassword  : String; { Password; won't be shown          }
  18.     CStartDir  : String; { Starting directory; used for FTP  }
  19.   end;
  20.   { Array of TCR }
  21.   CRFile = file of TConnectionsRecord; { File type for TCRec }
  22.   { This record is used to hold information about a newsgroup            }
  23.   { NOTE : hi and low pointers indicate either dl or trashing without dl }
  24.   { "read" is for an article dl'd but not trashed.                       }
  25.   PNewsGroupRecord = ^TNewsGroupRecord;
  26.   TNewsGroupRecord = record
  27.     GName                : String;  { Profile of the newsgroup              }
  28.     GRealName            : String;  { Real Newsrc name of the newsgroup     }
  29.     GLowest              : Longint; { Number of lowest dl/trashed article   }
  30.     GHighest             : Longint; { Number of highest dl/trashed article  }
  31.     GTotalNew            : Longint; { Total New articles available          }
  32.     GTotalAvailable      : Longint; { After update, shows how many arts on s}
  33.     GLowestAvailable     : Longint; { au, shows lowest a# on server         }
  34.     GHighestAvailable    : Longint; { au, shows highest a# on server        }
  35.     GPostable            : Boolean; { Can post to newsgroup                 }
  36.     GSubscribed          : Boolean; { Subscribed to newsgroup               }
  37.     GTotalArticles       : Longint; { Total articles maintained on system   }
  38.     GTotalUnReadArticles : Longint; { Total unread articles on system       }
  39.     GIDNumber            : Integer;
  40.     GFileName            : String;  { Name of file holding articles records }
  41.     GLTag                : Longint; { Tag field to hold pointer to arts TL  }
  42.   end;
  43.   NGRFile = file of TNewsGroupRecord; { File type for NGRec }
  44.   { This record is used to hold information about Newsgroup articles }
  45.   PNewsGroupArticleRecord = ^TNewsGroupArticleRecord;
  46.   TNewsGroupArticleRecord = record
  47.     NGAGroupname   : String;  { Newsgroup name (redundancy safeguard)     }
  48.     NGASubject     : String;  { Subject of article                        }
  49.     NGANumber      : Longint; { Article number                            }
  50.     NGADownloaded  : boolean; { Article attempted/succeeded downloading   }
  51.     NGASender      : String;  { Article's putative sender (CIUPKC158=us)  }
  52.     NGARead        : Boolean; { Article read flag                         }
  53.     NGAPosted      : Boolean; { Article posted flag                       }
  54.     NGAArtFileName : String;  { Name of system-gen file with article text }
  55.   end;
  56.   NGARFile = file of TNewsGroupArticleRecord;
  57.   { This record is used to hold information about EMail Mailboxes }
  58.   PEMailMailBoxRecord = ^TEMailMailBoxRecord;
  59.   TEMailMailBoxRecord = record
  60.     MBName        : String;  { Name of the mailbox                     }
  61.     MBIDNumber    : Integer;
  62.     MBMaxMsgNumber : Longint;
  63.     MBTotal       : Longint; { Total Mail Messages in Mailbox          }
  64.     MBUnReadTotal : Longint; { Total unread Mail Messages in Mailbox   }
  65.     MBUnSentTotal : Longint; { Total unsent Mail Messages in Mailbox   }
  66.     MBMsgFileName : String;  { Name of file holding Messages records   }
  67.     MBLTag        : Longint; { Tag to pointer to Tlist holding msgrecs }
  68.   end;
  69.   EMMBRFile = file of TEMailMailBoxRecord; { File type for EMMBRec }
  70.   { This record is used to hold information about EMail messages in a Mailbox }
  71.   PEMailMessageRecord = ^TEMailMessageRecord;
  72.   TEMailMessageRecord = record
  73.     MRMailBoxName      : String;  { Name of mailbox (redundancy safeguard)       }
  74.     MRMessageSubject   : String;  { Subject of the Message                       }
  75.     MRMessageRecipient : String;  { EMail address of primary recipient           }
  76.     MRMessageSender    : String;  { EMail address of sender                      }
  77.     MRCarbonCopy       : String;  { EMail CC recips; "|" delimited               }
  78.     MRBlindCarbonCopy  : String;  { EMail BCC recips; "|" delimited              }
  79.     MRDateTime         : String;  { EMail date/time field                        }
  80.     MRRead             : Boolean; { EMail Read flag                              }
  81.     MRSent             : Boolean; { EMail Send flag                              }
  82.     MRFileName         : String;  { EMail system generated filename for msg text }
  83.   end;
  84.   EMMRFile = file of TEMailMessageRecord; { File type for EMMRec }
  85.   TCCINetCCForm = class(TForm)
  86.     MainMenu1: TMainMenu;
  87.     Network1: TMenuItem;
  88.     N1: TMenuItem;
  89.     Exit1: TMenuItem;
  90.     Services1: TMenuItem;
  91.     IPAddress1: TMenuItem;
  92.     EMail1: TMenuItem;
  93.     FTP1: TMenuItem;
  94.     UsenetNws1: TMenuItem;
  95.     Panel1: TPanel;
  96.     Panel2: TPanel;
  97.     Panel3: TPanel;
  98.     Panel4: TPanel;
  99.     Panel5: TPanel;
  100.     Panel6: TPanel;
  101.     ListBox1: TListBox;
  102.     Panel7: TPanel;
  103.     SpeedButton1: TSpeedButton;
  104.     SpeedButton2: TSpeedButton;
  105.     ListBox2: TListBox;
  106.     ComboBox1: TComboBox;
  107.     Button1: TButton;
  108.     Memo1: TMemo;
  109.     Files1: TMenuItem;
  110.     Edit1: TMenuItem;
  111.     Encoding1: TMenuItem;
  112.     EMail2: TMenuItem;
  113.     FTP2: TMenuItem;
  114.     News1: TMenuItem;
  115.     Load1: TMenuItem;
  116.     Save1: TMenuItem;
  117.     Cut1: TMenuItem;
  118.     Copy1: TMenuItem;
  119.     CopytoFile1: TMenuItem;
  120.     Paste1: TMenuItem;
  121.     PastefromFile1: TMenuItem;
  122.     UUDecode1: TMenuItem;
  123.     MIMEDecode1: TMenuItem;
  124.     UUEncode1: TMenuItem;
  125.     MIMEEncode1: TMenuItem;
  126.     CheckMail1: TMenuItem;
  127.     ReplyToCurrentMessage1: TMenuItem;
  128.     SendCurrentMessage1: TMenuItem;
  129.     SendQueue1: TMenuItem;
  130.     Mailboxes1: TMenuItem;
  131.     Correspondents1: TMenuItem;
  132.     EmptyTrash1: TMenuItem;
  133.     SpeedButton4: TSpeedButton;
  134.     SpeedButton5: TSpeedButton;
  135.     SpeedButton3: TSpeedButton;
  136.     Panel8: TPanel;
  137.     Label1: TLabel;
  138.     Label2: TLabel;
  139.     ComboBox2: TComboBox;
  140.     Label3: TLabel;
  141.     ComboBox3: TComboBox;
  142.     ConnectToSite1: TMenuItem;
  143.     Disconnect1: TMenuItem;
  144.     UploadMarked1: TMenuItem;
  145.     DownloadMarked1: TMenuItem;
  146.     Directory1: TMenuItem;
  147.     ASCII1: TMenuItem;
  148.     Binary1: TMenuItem;
  149.     ASCII2: TMenuItem;
  150.     Binary2: TMenuItem;
  151.     ViewRemoteasText1: TMenuItem;
  152.     FTPSites1: TMenuItem;
  153.     CheckNewNews1: TMenuItem;
  154.     GetMarked1: TMenuItem;
  155.     CreateNewMessage1: TMenuItem;
  156.     Article1: TMenuItem;
  157.     SubscribedNewsgroups1: TMenuItem;
  158.     Trash1: TMenuItem;
  159.     Preferences1: TMenuItem;
  160.     EMail3: TMenuItem;
  161.     FTP3: TMenuItem;
  162.     News2: TMenuItem;
  163.     Label4: TLabel;
  164.     Label5: TLabel;
  165.     ViewasText1: TMenuItem;
  166.     Change1: TMenuItem;
  167.     Create1: TMenuItem;
  168.     Delete3: TMenuItem;
  169.     ChangeLocal1: TMenuItem;
  170.     OpenDialog1: TOpenDialog;
  171.     SaveDialog1: TSaveDialog;
  172.     Paths1: TMenuItem;
  173.     ProgressInfo1: TMenuItem;
  174.     N2: TMenuItem;
  175.     ViewInEditWindow1: TMenuItem;
  176.     ViewInStatusLine1: TMenuItem;
  177.     SaveToFile1: TMenuItem;
  178.     ViewWinsockInfo1: TMenuItem;
  179.     Description1: TMenuItem;
  180.     SystemStatus1: TMenuItem;
  181.     VendorSpecific1: TMenuItem;
  182.     Gauge1: TGauge;
  183.     NewsServers1: TMenuItem;
  184.     AllReadArticles1: TMenuItem;
  185.     AllMarkedArticles1: TMenuItem;
  186.     AllAvailableArticles1: TMenuItem;
  187.     NewArticle1: TMenuItem;
  188.     FollowupArticle1: TMenuItem;
  189.     Post1: TMenuItem;
  190.     CurrentArticle1: TMenuItem;
  191.     EntireQueue1: TMenuItem;
  192.     ConnectandUpdate1: TMenuItem;
  193.     Disconnect2: TMenuItem;
  194.     Headers1: TMenuItem;
  195.     RetrieveMarked1: TMenuItem;
  196.     RetrieveAll1: TMenuItem;
  197.     DownloadActiveNewsgroups1: TMenuItem;
  198.     PutinQueue1: TMenuItem;
  199.     TrashMarkedMessages1: TMenuItem;
  200.     MailServers1: TMenuItem;
  201.     ExitEMailRequired1: TMenuItem;
  202.     ToCurrentMessage1: TMenuItem;
  203.     ToNewMessage1: TMenuItem;
  204.     ToFile2: TMenuItem;
  205.     AbortNewsgroupDownload1: TMenuItem;
  206.     Catchup1: TMenuItem;
  207.     Marked1: TMenuItem;
  208.     All1: TMenuItem;
  209.     File1: TMenuItem;
  210.     SelectedArticle1: TMenuItem;
  211.     SelectMultipleArticles1: TMenuItem;
  212.     DecodeSelections1: TMenuItem;
  213.     procedure Exit1Click(Sender: TObject);
  214.     procedure FormCreate(Sender: TObject);
  215.     procedure FormDestroy(Sender: TObject);
  216.     procedure Description1Click(Sender: TObject);
  217.     procedure SystemStatus1Click(Sender: TObject);
  218.     procedure VendorSpecific1Click(Sender: TObject);
  219.     procedure ViewInEditWindow1Click(Sender: TObject);
  220.     procedure ViewInStatusLine1Click(Sender: TObject);
  221.     procedure SaveToFile1Click(Sender: TObject);
  222.     procedure IPAddress1Click(Sender: TObject);
  223.     procedure FTP1Click(Sender: TObject);
  224.     procedure FormResize(Sender: TObject);
  225.     procedure FTPSites1Click(Sender: TObject);
  226.     procedure FTP3Click(Sender: TObject);
  227.     procedure ConnectToSite1Click(Sender: TObject);
  228.     procedure Button1Click(Sender: TObject);
  229.     procedure ViewasText1Click(Sender: TObject);
  230.     procedure Disconnect1Click(Sender: TObject);
  231.     procedure ToDisplay1Click(Sender: TObject);
  232.     procedure ToFile1Click(Sender: TObject);
  233.     procedure Binary2Click(Sender: TObject);
  234.     procedure Change1Click(Sender: TObject);
  235.     procedure ChangeLocal1Click(Sender: TObject);
  236.     procedure ListBox1DblClick(Sender: TObject);
  237.     procedure ListBox2DblClick(Sender: TObject);
  238.     procedure ASCII1Click(Sender: TObject);
  239.     procedure DeleteRemoteFiles1Click(Sender: TObject);
  240.     procedure Binary1Click(Sender: TObject);
  241.     procedure Delete3Click(Sender: TObject);
  242.     procedure Create1Click(Sender: TObject);
  243.     procedure ListBox1Click(Sender: TObject);
  244.     procedure UsenetNws1Click(Sender: TObject);
  245.     procedure Disconnect2Click(Sender: TObject);
  246.     procedure News2Click(Sender: TObject);
  247.     procedure ConnectandUpdate1Click(Sender: TObject);
  248.     procedure CheckNewNews1Click(Sender: TObject);
  249.     procedure NewsServers1Click(Sender: TObject);
  250.     procedure SubscribedNewsgroups1Click(Sender: TObject);
  251.     procedure RetrieveMarked1Click(Sender: TObject);
  252.     procedure RetrieveAll1Click(Sender: TObject);
  253.     procedure GetMarked1Click(Sender: TObject);
  254.     procedure NewArticle1Click(Sender: TObject);
  255.     procedure FollowupArticle1Click(Sender: TObject);
  256.     procedure PutinQueue1Click(Sender: TObject);
  257.     procedure CurrentArticle1Click(Sender: TObject);
  258.     procedure EntireQueue1Click(Sender: TObject);
  259.     procedure AllReadArticles1Click(Sender: TObject);
  260.     procedure AllMarkedArticles1Click(Sender: TObject);
  261.     procedure AllAvailableArticles1Click(Sender: TObject);
  262.     procedure DownloadActiveNewsgroups1Click(Sender: TObject);
  263.     procedure UUEncode1Click(Sender: TObject);
  264.     procedure Load1Click(Sender: TObject);
  265.     procedure Save1Click(Sender: TObject);
  266.     procedure EMail1Click(Sender: TObject);
  267.     procedure CheckMail1Click(Sender: TObject);
  268.     procedure MailServers1Click(Sender: TObject);
  269.     procedure Mailboxes1Click(Sender: TObject);
  270.     procedure Correspondents1Click(Sender: TObject);
  271.     procedure EMail3Click(Sender: TObject);
  272.     procedure Paths1Click(Sender: TObject);
  273.     procedure ExitEMailRequired1Click(Sender: TObject);
  274.     procedure TrashMarkedMessages1Click(Sender: TObject);
  275.     procedure EmptyTrash1Click(Sender: TObject);
  276.     procedure MIMEDecode1Click(Sender: TObject);
  277.     procedure Cut1Click(Sender: TObject);
  278.     procedure Copy1Click(Sender: TObject);
  279.     procedure CopytoFile1Click(Sender: TObject);
  280.     procedure Paste1Click(Sender: TObject);
  281.     procedure PastefromFile1Click(Sender: TObject);
  282.     procedure SpeedButton5Click(Sender: TObject);
  283.     procedure SpeedButton3Click(Sender: TObject);
  284.     procedure SpeedButton1Click(Sender: TObject);
  285.     procedure SpeedButton2Click(Sender: TObject);
  286.     procedure ListBox2Click(Sender: TObject);
  287.     procedure AbortNewsgroupDownload1Click(Sender: TObject);
  288.     procedure Marked1Click(Sender: TObject);
  289.     procedure All1Click(Sender: TObject);
  290.     procedure File1Click(Sender: TObject);
  291.     procedure SelectedArticle1Click(Sender: TObject);
  292.     procedure SelectMultipleArticles1Click(Sender: TObject);
  293.     procedure DecodeSelections1Click(Sender: TObject);
  294.     procedure SpeedButton4Click(Sender: TObject);
  295.   private
  296.     { Private declarations }
  297.   public
  298.     { Public declarations }
  299.     procedure EnableFTPMenus;
  300.     procedure DisableFTPMenus;
  301.     procedure EnableNNTPMenus;
  302.     procedure DisableNNTPMenus;
  303.     procedure EnablePOP3SMTPMenus;
  304.     procedure DisablePOP3SMTPMenus;
  305.     procedure UpdateGauge( BytesFinished , TotalToHandle : longint );
  306.     procedure UpdateMailGauge( BytesFinished , TotalToHandle : longint );
  307.     procedure UpdateMIMEGauge( BytesFinished , TotalToHandle : longint );
  308.     procedure UpdateUUGauge( BytesFinished , TotalToHandle : longint );
  309.     function DoFTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  310.     function DoNNTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  311.     function DoPOP3Connection( PCRPointer : PConnectionsRecord ) : boolean;
  312.     procedure DoFTPDisconnect;
  313.     procedure DoNNTPDisconnect;
  314.     procedure DoPOP3SMTPDisconnect;
  315.     procedure ReadIniData;
  316.     procedure WriteIniData;
  317.     procedure LoadFTPSiteFile;
  318.     procedure LoadNNTPSiteFile;
  319.     procedure LoadEmailServerFile;
  320.     procedure SaveEMailServerFile;
  321.     procedure LoadEmailMailboxFile( WhichServer : Integer );
  322.     procedure SaveEMailMailboxFile( WhichServer : Integer );
  323.     procedure LoadEmailCorrespondentsFile;
  324.     procedure SaveEMailCorrespondentsFile;
  325.     procedure SetupEMailServerStatus;
  326.     procedure SetupNNTPServersInfoDisplay;
  327.     procedure SaveFTPSiteFile;
  328.     procedure SetupFTPSiteLists;
  329.     procedure SaveNNTPSiteFile;
  330.     procedure SetupNNTPSiteLists;
  331.     procedure SetupNNTPNewsGroupsInfoDisplay;
  332.     procedure SetupNNTPNewsGroupLists;
  333.     procedure SaveNNTPNewsGroupLists;
  334.     procedure SetupNewsGroupListboxes;
  335.     procedure SetupEMailListboxes;
  336.     procedure SetupMailboxLists;
  337.     procedure SetupEMailServersInfoDisplay;
  338.     procedure SetupEMailMailboxInfoDisplay;
  339.     procedure PopulateLB2WithArticleHeaders;
  340.     procedure PopulateLB2WithMessageHeaders;
  341.     procedure SetupEMailCorrespondentsInfoDisplay;
  342.     procedure AddNullTermTextToMemo( TheTextToAdd   : String;
  343.                                      TheMemoToAddTo : TMemo   );
  344.     function AddNullTermTextToLabel( TheTextToAdd   : String ) : String;
  345.     procedure SetHGCursors;
  346.     procedure SetNormalCursors;
  347.     procedure AddProgressText( WhatText : String );
  348.     procedure ShowProgressText( WhatText : String );
  349.     procedure ShowProgressErrorText( WhatText : String );
  350.     procedure SocketsErrorOccurred( Sender     : TObject;
  351.                                      ErrorCode  : Integer;
  352.                                      TheMessage : String   );
  353.   end;
  354.   { Component to hold FTP handling capabilities }
  355.   TFTPComponent = class( TWinControl )
  356.   public
  357.     FTPCommandInProgress ,
  358.     Connection_Established : Boolean;
  359.     Socket1 : TCCSocket;
  360.     Socket2 : TCCSocket;
  361.     constructor Create( AOwner : TComponent ); override;
  362.     destructor Destroy; override;
  363.     function GetTotalBytesToReceive( TheString : String ) : Longint;
  364.     function StripBrackets( TheString : String ) : String;
  365.     function GetShortPathname( TheString : String ) : String;
  366.     function GetWin16FileName( InputName : String ) : String;
  367.     function GetRemoteWorkingDirectory( var RemoteDir : String ) : Boolean;
  368.     function SetRemoteDirectory( TheDir : String ) : Boolean;
  369.     function DeleteRemoteDirectory( TheDir : String ) : Boolean;
  370.     function CreateRemoteDirectory( TheDir : String ) : Boolean;
  371.     function DeleteRemoteFile( TheFileName : String ) : Boolean;
  372.     function EstablishConnection( PCRPointer : PConnectionsRecord ) : Boolean;
  373.     function LoginUser( PCRPointer : PConnectionsRecord ) : Boolean;
  374.     function SendPassword( PCRPointer : PConnectionsRecord ) : Boolean;
  375.     function SetRemoteStartupDirectory( PCRPointer : PConnectionsRecord )
  376.               : Boolean;
  377.     function GetRemoteDirectoryListing( TheListBox : TListBox ) : Boolean;
  378.     function GetRemoteDirectoryListingToMemo : Boolean;
  379.     procedure SendASCIILocalFile( LocalName : String );
  380.     procedure SendBinaryLocalFile( LocalName : String );
  381.     procedure ReceiveASCIIRemoteFile( RemoteName , LocalName : String );
  382.     procedure ReceiveBinaryRemoteFile( RemoteName , LocalName : String );
  383.     function GetLocalDirectoryAndListing( var TheString : String;
  384.                                               TheListBox : TListBox )
  385.               : Boolean;
  386.     function GetUNIXTextString( var StringIn : String ) : String;
  387.     procedure ReceiveASCIIRemoteFileToMemo( RemoteName : String );
  388.     function GetListeningPort : Integer;
  389.     procedure GetFileNameFromUNIXFileName( var TheName : String );
  390.     function Disconnect : Boolean;
  391.     function DoCStyleFormat(       TheText      : string;
  392.                              const TheArguments : array of const ) : String;
  393.     procedure UpdateGauge( BytesFinished , TotalToHandle : longint );
  394.     function GetQuotedString( TheString : String ) : String;
  395.     procedure AddProgressText( WhatText : String );
  396.     procedure ShowProgressText( WhatText : String );
  397.     procedure ShowProgressErrorText( WhatText : String );
  398.     function GetFTPServerResponse( var ResponseString : String ) : integer;
  399.     procedure FTPSocketsErrorOccurred( Sender     : TObject;
  400.                                      ErrorCode  : Integer;
  401.                                      TheMessage : String   );
  402.     function PerformFTPCommand(
  403.                     TheCommand   : string;
  404.               const TheArguments : array of const ) : Integer;
  405.   end;
  406. const
  407.   POV_MEMO                 = 1; { Progress to the Memo           }
  408.   POV_STAT                 = 2; { Progress to the status caption }
  409.   TCPIP_STATUS_PRELIMINARY   = 1; { Wait; command being processed  }
  410.   TCPIP_STATUS_COMPLETED     = 2; { Done; command fully succeded   }
  411.   TCPIP_STATUS_CONTINUING    = 3; { OK; send more data to finish   }
  412.   TCPIP_STATUS_RETRY_COMMAND = 4; { Temporary Error; try cmd again }
  413.   TCPIP_STATUS_FATAL_ERROR   = 5; { Fatal Error; don't retry cmd   }
  414.  
  415. var
  416.   CCINetCCForm         : TCCINetCCForm;
  417.   GlobalErrorCode      : Integer;        { Used to pass around error info  }
  418.   GlobalAbortedFlag    : Boolean;        { Used to signal timeout error    }
  419.   ProgressList         : TStringList;    { Used to hold progress text info }
  420.   ProgressFileName     : String;         { Used to hold progress file name }
  421.   ProgressOutputVector : Integer;        { Used to direct progress output  }
  422.   TheFTPSiteList       : TList;          { Used to store the FTP site recs }
  423.   TheWorkingFTPSL      : TList;          { Used to store working copy of l }
  424.   TheNewsServerList    : TList;          { Used to hold list of NNTP servs }
  425.   TheWorkingNSSL       : TList;          { Used for working copy of above  }
  426.   TheEMailServerList   : TList;          { Used for list of POP3/SMTP serv }
  427.   TheWorkingEMSL       : TList;          { Used for working copy of above  }
  428.   TheNewsRCList        : TList;          { Used for list of available ngs  }
  429.   TheWorkingNRCSL      : TList;          { Used for working copy of above  }
  430.   TheNGArticlesList    : TList;          { Used for current articles list  }
  431.                                          { (will hot swap from pointer of  }
  432.                                          {  Tlist of Tlists in base rec.)  }
  433.   TheEMailMailboxList  : TList;          { Used for list of available mbs  }
  434.   TheWorkingMBSL       : TList;          { Used for working copy of above  }
  435.   TheCorrespondentsList: TList;          { Used for list of correspondents }
  436.   TheWorkingCPSL       : TList;          { Used for working copy of above  }
  437.   TheMBMessagesList    : TList;          { Used for current msgs; hotswaps }
  438.   TheEMailServerFile   : CRFile;         { File of Email servers records   }
  439.   TheEMailCorrespondentsFile : CRFile;
  440.   TheNewsServerFile    : CRFile;         { File of NNTP servers records    }
  441.   TheNewsRCFile        : NGRFile;        { File of Newsgroups records      }
  442.   TheNewsArticleFile   : NGARFile;       { Current ng articles records file}
  443.   TheEMailMailboxFile  : EMMBRFile;      { File of Mailboxes records       }
  444.   TheEMailMessagesFile : EMMRFile;       { Current mb messages records file}
  445.   TheFTPSiteFile       : CRFile;         { Used to load the FTP site file  }
  446.   TheICCIniFile        : TIniFile;       { Used to retrieve the INI File   }
  447.   MailPath             : String;         { Used for path to Mail Files     }
  448.   NewsPath             : String;         { Used for path to News Files     }
  449.   FTPPath              : String;         { Used for path to FTP Files      }
  450.   CurrentPassWordString : String;        { Used to hold login id for anons }
  451.   CurrentEMPassWordString : String;      { Used to hold login id for anons }
  452.   PassWordControlVector : Integer;       { Used to hold display of pw vect }
  453.   CurrentRealPWString   : String;        { Used to hold a real password    }
  454.   EMPassWordControlVector : Integer;       { Used to hold display of pw vect }
  455.   CurrentEMRealPWString   : String;        { Used to hold a real password    }
  456.   TheFTPComponent       : TFTPComponent; { FTP Object                      }
  457.   TheLine ,
  458.   HolderLine ,
  459.   GlobalTextBuffer      : String;
  460.   TheAnonRedialVector ,
  461.   DefaultDownloadVector : Integer;
  462.   NewsReadArticlePurgingVector : Integer;
  463.   NewsPostQueueingVector : Integer;
  464.   NewsReadArticleDisplayVector : Integer;
  465.   NewsUUMIMEVector : Integer;
  466.   NewsInitialUpdateVector : Integer;
  467.   LeftoverText          : String;
  468.   LeftoversOnTable      : Boolean;
  469.   FileNameToXFer        : String;
  470.   WhichServer           : Integer;       { Holds current NNTP server }
  471.   WhichGroup            : Integer;       { Holds current NNTP newsgroup }
  472.   TheUUObject           : TUUCodingObject;
  473.   EMRemoteDeletionVector : Integer;
  474.   EMChokeVector : Integer;
  475.   EMDefaultDownloadVector : Integer;
  476.   EMQueueVector : Integer;
  477.   NewsgroupListLoaded ,
  478.   EmailLoaded ,
  479.   NewMessageInProgress : Boolean;
  480.   TheUUDecodeList      : TStringList;
  481.   
  482. implementation
  483.  
  484. uses CCICCPOP, CCICNNTP;
  485.  
  486. var
  487.   TheNNTPComponent      : TNNTPComponent;{ NNTP News Object                }
  488.  
  489. {$R *.DFM}
  490.  
  491.  
  492. { This procedure actually attempts to connect to the internet at an POP3SMTP site }
  493. function TCCINetCCForm.DoPOP3Connection( PCRPointer : PConnectionsRecord ) : boolean;
  494. begin
  495.   { Create the component }
  496.   Result := false;
  497.   { Do busy cursors }
  498.   SetHGCursors;
  499.   if not ThePOP3SMTPComponent.EstablishPOP3Connection( PCRPointer ) then
  500.   begin
  501.     { Do saved cursors }
  502.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  503.     ThePOP3SMTPComponent.Connection_Established := false;
  504.     SetNormalCursors;
  505.     exit;
  506.   end;
  507.   if not ThePOP3SMTPComponent.LoginUser( PCRPointer ) then
  508.   begin
  509.     { Do saved cursors }
  510.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  511.     ThePOP3SMTPComponent.Connection_Established := false;
  512.     SetNormalCursors;
  513.     exit;
  514.   end;
  515.   if not ThePOP3SMTPComponent.SendPassword( PCRPointer ) then
  516.   begin
  517.     { Do saved cursors }
  518.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  519.     ThePOP3SMTPComponent.Connection_Established := false;
  520.     SetNormalCursors;
  521.     exit;
  522.   end;
  523.   SetNormalCursors;
  524.   Result := true;
  525.   EnablePOP3SMTPMenus;
  526.   ThePOP3SMTPComponent.POP3CommandInProgress := false;
  527.   Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  528. end;
  529.  
  530. { This procedure actually attempts to disconnect to the internet at an ftp site}
  531. procedure TCCINetCCForm.DoPOP3SMTPDisconnect;
  532. begin
  533.   { Kill the socket }
  534.   ThePOP3SMTPComponent.Socket1.CCSockClose;
  535.   ThePOP3SMTPComponent.Connection_Established := false;
  536. end;
  537.  
  538. { Procedure to load the POP3SMTP Site list }
  539. procedure TCCINetCCForm.LoadEmailServerFile;
  540. var ThePSSRecord : PConnectionsRecord; { Generic TCR Pointer    }
  541.     PSSLName     : String;             { POP3SMTP Site List filename }
  542.     Counter_1    : Integer;            { Loop counter           }
  543. begin
  544.   { Create the sites list list }
  545.   TheEMailServerList := TList.Create;
  546.   { Set up the FTP sites list file name }
  547.   PSSLName := MailPath + '\PSSERVER.TCR';
  548.   { If the FTP Site List exists load it in }
  549.   if FileExists( PSSLName ) then
  550.   begin
  551.     { set up the file and open it }
  552.     AssignFile( TheEMailServerFile , PSSLName );
  553.     Reset( TheEMailServerFile );
  554.     { read in the records }
  555.     for Counter_1 := 0 to FileSize( TheEMailServerFile ) - 1 do
  556.     begin
  557.       { Create the TCRecord }
  558.       New( ThePSSRecord );
  559.       { Read in the data record }
  560.       Seek( TheEMailServerFile , Counter_1 );
  561.       Read( TheEMailServerFile , ThePSSRecord^ );
  562.       { Add the record to the list }
  563.       TheEMailServerList.Add( ThePSSRecord );
  564.     end;
  565.     { close the file }
  566.     CloseFile( TheEMailServerFile );
  567.   end
  568.   else
  569.   { Otherwise create a default one with the a generic mail site (?) }
  570.   begin
  571.     { create new record }
  572.     New( ThePSSRecord );
  573.     { fill in its info }
  574.     with ThePSSRecord^ do
  575.     begin
  576.       CProfile   := 'My Mail Server';
  577.       CIPAddress := 'mail.myprovider.com';
  578.       CUserName  := 'myname';
  579.       CPassword  := 'mypassword';
  580.       CStartDir  := 'myname@myprovider.com';
  581.     end;
  582.     { add it to the list }
  583.     { do it three more times }
  584.     TheEMailServerList.Add( ThePSSRecord );
  585.     { create the file and write out the data, then close it }
  586.     AssignFile( TheEMailServerFile , PSSLName );
  587.     Rewrite( TheEMailServerFile );
  588.     ThePSSRecord :=
  589.        PConnectionsRecord( TheEMailServerList.Items[ 0 ] );
  590.       Seek( TheEMailServerFile , 0 );
  591.       Write( TheEMailServerFile , ThePSSRecord^ );
  592.     CloseFile( TheEMailServerFile );
  593.   end;
  594.   TheWorkingEMSL := TList.Create;
  595.   For Counter_1 := 0 to TheEMailServerList.Count - 1 do
  596.   begin
  597.     New( ThePSSRecord );
  598.     ThePSSRecord^ := PConnectionsRecord( TheEMailServerList.Items[ Counter_1 ] )^;
  599.     TheWorkingEMSL.Add( ThePSSRecord );
  600.   end;
  601. end;
  602.  
  603. procedure TCCINetCCForm.SaveEMailServerFile;
  604. var ThePSSRecord : PConnectionsRecord; { The TC Record pointer   }
  605.     PSSLName     : String;             { POP3SMTP Site List filename }
  606.     Counter_1    : Integer;            { Loop counter           }
  607. begin
  608.   { Set up the file name }
  609.   PSSLName := MailPath + '\PSSERVER.TCR';
  610.   { Assign the file }
  611.   AssignFile( TheEMailServerFile , PSSLName );
  612.   { Rewrite it }
  613.   Rewrite( TheEMailServerFile );
  614.   { run the list through the procedure }
  615.   for Counter_1 := 0 to TheEMailServerList.Count - 1 do
  616.   begin
  617.     { get the record from the list }
  618.     ThePSSRecord :=
  619.      PConnectionsRecord( TheEMailServerList.Items[ Counter_1 ] );
  620.     { Do the seek/write }
  621.     Seek( TheEMailServerFile , Counter_1 );
  622.     Write( TheEMailServerFile , ThePSSRecord^ );
  623.     { free the record }
  624.     Dispose( ThePSSRecord );
  625.   end;
  626.   { Close the file }
  627.   CloseFile( TheEMailServerFile );
  628.   { Free the list pointers }
  629.   TheEMailServerList.Free;
  630.   for Counter_1 := 0 to TheWorkingEMSL.Count - 1 do
  631.   begin
  632.     ThePSSRecord := PConnectionsRecord( TheWorkingEMSL.Items[ Counter_1 ] );
  633.     Dispose( ThePSSRecord );
  634.   end;
  635.   TheWorkingEMSL.Free;
  636. end;
  637.  
  638. { Procedure to load the POP3SMTP Site list }
  639. procedure TCCINetCCForm.LoadEmailMailboxFile( WhichServer : Integer );
  640. var TheMBRecord : PEMailMailboxRecord; { Generic TCR Pointer    }
  641.     PSMBName    : String;              { Mailbox filename       }
  642.     Counter_1   ,
  643.     Counter_2   : Integer;             { Loop counter           }
  644.     TheMessagesList : TList;
  645.     TheEMMRecord : PEMailMessageRecord;
  646. begin
  647.   { Create the sites list list }
  648.   TheEMailMailboxList := TList.Create;
  649.   { Set up the FTP sites list file name }
  650.   PSMBName := MailPath + '\MAILBX' + IntToStr( WhichServer ) + '.MBX';
  651.   { If the FTP Site List exists load it in }
  652.   if FileExists( PSMBName ) then
  653.   begin
  654.     { set up the file and open it }
  655.     AssignFile( TheEMailMailboxFile , PSMBName );
  656.     Reset( TheEMailMailboxFile );
  657.     { read in the records }
  658.     for Counter_1 := 0 to FileSize( TheEMailMailboxFile ) - 1 do
  659.     begin
  660.       { Create the TCRecord }
  661.       New( TheMBRecord );
  662.       { Read in the data record }
  663.       Seek( TheEMailMailboxFile , Counter_1 );
  664.       Read( TheEMailMailboxFile , TheMBRecord^ );
  665.       { Add the record to the list }
  666.       TheEMailMailboxList.Add( TheMBRecord );
  667.     end;
  668.     { close the file }
  669.     CloseFile( TheEMailMailboxFile );
  670.   end
  671.   else
  672.   { Otherwise create a default one with the In and Out mailboxes (?) }
  673.   begin
  674.     { create new record }
  675.     New( TheMBRecord );
  676.     { fill in its info }
  677.     with TheMBRecord^ do
  678.     begin
  679.       MBName         := 'In Box';
  680.       MBIDNumber     := 1;
  681.       MBMaxMsgNumber := 0;
  682.       MBTotal        := 0;
  683.       MBUnReadTotal  := 0;
  684.       MBUnSentTotal  := 0;
  685.       MBMsgFileName  := 'MB1.MBX';
  686.       MBLTag         := 0;
  687.     end;
  688.     { add it to the list }
  689.     TheEMailMailboxList.Add( TheMBRecord );
  690.     { create new record }
  691.     New( TheMBRecord );
  692.     { fill in its info }
  693.     with TheMBRecord^ do
  694.     begin
  695.       MBName         := 'Out Box';
  696.       MBIDNumber     := 2;
  697.       MBMaxMsgNumber := 0;
  698.       MBTotal        := 0;
  699.       MBUnReadTotal  := 0;
  700.       MBUnSentTotal  := 0;
  701.       MBMsgFileName  := 'MB2.MBX';
  702.       MBLTag         := 0;
  703.     end;
  704.     { add it to the list }
  705.     TheEMailMailboxList.Add( TheMBRecord );
  706.     { create the file and write out the data, then close it }
  707.     AssignFile( TheEMailMailboxFile , PSMBName );
  708.     Rewrite( TheEMailMailboxFile );
  709.     TheMBRecord :=
  710.        PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] );
  711.       Seek( TheEMailMailboxFile , 0 );
  712.       Write( TheEMailMailboxFile , TheMBRecord^ );
  713.     TheMBRecord :=
  714.        PEMailMailboxRecord( TheEMailMailboxList.Items[ 1 ] );
  715.       Seek( TheEMailMailboxFile , 1 );
  716.       Write( TheEMailMailboxFile , TheMBRecord^ );
  717.     CloseFile( TheEMailMailboxFile );
  718.   end;
  719.   { Load in Message Records and create storage lists }
  720.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  721.   begin
  722.     PSMBName := PEMailMailboxRecord(
  723.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  724.     if FileExists( MailPath + '\' + PSMBName ) then
  725.     begin
  726.       TheMessagesList := TList.Create;
  727.       AssignFile( TheEMailMessagesFile , MailPath + '\' + PSMBName );
  728.       Reset( TheEMailMessagesFile );
  729.       for Counter_2 := 0 to FileSize( TheEMailMessagesFile ) - 1 do
  730.       begin
  731.         New( TheEMMRecord );
  732.         Seek( TheEMailMessagesFile , Counter_2 );
  733.         Read( TheEMailMessagesFile , TheEMMRecord^ );
  734.         TheMessagesList.Add( TheEMMRecord );
  735.       end;
  736.       CloseFile( TheEMailMessagesFile );
  737.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  738.        Longint( TheMessagesList );
  739.     end
  740.     else
  741.     begin
  742.       TheMessagesList := TList.Create;
  743.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  744.        Longint( TheMessagesList );
  745.     end;
  746.   end;
  747.   TheWorkingMBSL := TList.Create;
  748.   For Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  749.   begin
  750.     New( TheMBRecord );
  751.     TheMBRecord^ := PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^;
  752.     TheWorkingMBSL.Add( TheMBRecord );
  753.   end;
  754. end;
  755.  
  756. procedure TCCINetCCForm.SaveEMailMailboxFile( WhichServer : Integer );
  757. var TheMBRecord : PEMailMailboxRecord; { Generic TCR Pointer    }
  758.     PSMBName    : String;              { Mailbox filename       }
  759.     Counter_2 ,
  760.     Counter_1   : Integer;             { Loop counter           }
  761.     TheList     : TList;
  762.     TheEMMRecord : PEMailMessageRecord;
  763. begin
  764.   { Load in Message Records and create storage lists }
  765.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  766.   begin
  767.     PSMBName := PEMailMailboxRecord(
  768.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  769.     TheList := TList( PEMailMailboxRecord(
  770.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag );
  771.     AssignFile( TheEMailMessagesFile , Mailpath + '\' + PSMBName );
  772.     Rewrite( TheEMailMessagesFile );
  773.     for Counter_2 := 0 to TheList.Count - 1 do
  774.     begin
  775.       TheEMMRecord := PEMailMessageRecord( TheList.Items[ Counter_2 ] );
  776.       Seek( TheEMailMessagesFile , Counter_2 );
  777.       Write( TheEMailMessagesFile , TheEMMRecord^ );
  778.       Dispose( TheEMMRecord );
  779.     end;
  780.     CloseFile( TheEMailMessagesFile );
  781.     TheList.Free;
  782.   end;
  783.   { Set up the file name }
  784.   PSMBName := MailPath + '\MAILBX' + IntToStr( WhichServer ) + '.MBX';
  785.   { Assign the file }
  786.   AssignFile( TheEMailMailboxFile , PSMBName );
  787.   { Rewrite it }
  788.   Rewrite( TheEMailMailboxFile );
  789.   { run the list through the procedure }
  790.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  791.   begin
  792.     { get the record from the list }
  793.     TheMBRecord :=
  794.      PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] );
  795.     { Do the seek/write }
  796.     Seek( TheEMailMailboxFile , Counter_1 );
  797.     Write( TheEMailMailboxFile , TheMBRecord^ );
  798.     { free the record }
  799.     Dispose( TheMBRecord );
  800.   end;
  801.   { Close the file }
  802.   CloseFile( TheEMailMailboxFile );
  803.   { Free the list pointers }
  804.   TheEMailMailboxList.Free;
  805.   for Counter_1 := 0 to TheWorkingMBSL.Count - 1 do
  806.   begin
  807.     TheMBRecord := PEMailMailboxRecord( TheWorkingMBSL.Items[ Counter_1 ] );
  808.     Dispose( TheMBRecord );
  809.   end;
  810.   TheWorkingMBSL.Free;
  811. end;
  812.  
  813. { Procedure to load the POP3SMTP Site list }
  814. procedure TCCINetCCForm.LoadEmailCorrespondentsFile;
  815. var ThePSSRecord : PConnectionsRecord; { Generic TCR Pointer    }
  816.     PSSLName     : String;             { POP3SMTP Site List filename }
  817.     Counter_1    : Integer;            { Loop counter           }
  818. begin
  819.   { Create the sites list list }
  820.   TheCorrespondentsList := TList.Create;
  821.   { Set up the FTP sites list file name }
  822.   PSSLName := MailPath + '\PSCORRSP.TCR';
  823.   { If the FTP Site List exists load it in }
  824.   if FileExists( PSSLName ) then
  825.   begin
  826.     { set up the file and open it }
  827.     AssignFile( TheEMailCorrespondentsFile , PSSLName );
  828.     Reset( TheEMailCorrespondentsFile );
  829.     { read in the records }
  830.     for Counter_1 := 0 to FileSize( TheEMailCorrespondentsFile ) - 1 do
  831.     begin
  832.       { Create the TCRecord }
  833.       New( ThePSSRecord );
  834.       { Read in the data record }
  835.       Seek( TheEMailCorrespondentsFile , Counter_1 );
  836.       Read( TheEMailCorrespondentsFile , ThePSSRecord^ );
  837.       { Add the record to the list }
  838.       TheCorrespondentsList.Add( ThePSSRecord );
  839.     end;
  840.     { close the file }
  841.     CloseFile( TheEMailCorrespondentsFile );
  842.   end
  843.   else
  844.   { Otherwise create a default one with the author }
  845.   begin
  846.     { create new record }
  847.     New( ThePSSRecord );
  848.     { fill in its info }
  849.     with ThePSSRecord^ do
  850.     begin
  851.       CProfile   := 'Nathan Wallace at TDE';
  852.       CIPAddress := 'kilgalen@tde.com';
  853.       CUserName  := '';
  854.       CPassword  := '';
  855.       CStartDir  := '';
  856.     end;
  857.     { add it to the list }
  858.     { do it three more times }
  859.     TheCorrespondentsList.Add( ThePSSRecord );
  860.     { create the file and write out the data, then close it }
  861.     AssignFile( TheEMailCorrespondentsFile , PSSLName );
  862.     Rewrite( TheEMailCorrespondentsFile );
  863.     ThePSSRecord :=
  864.        PConnectionsRecord( TheCorrespondentsList.Items[ 0 ] );
  865.       Seek( TheEMailCorrespondentsFile , 0 );
  866.       Write( TheEMailCorrespondentsFile , ThePSSRecord^ );
  867.     CloseFile( TheEMailCorrespondentsFile );
  868.   end;
  869.   TheWorkingCPSL := TList.Create;
  870.   For Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  871.   begin
  872.     New( ThePSSRecord );
  873.     ThePSSRecord^ := PConnectionsRecord( TheCorrespondentsList.Items[ Counter_1 ] )^;
  874.     TheWorkingCPSL.Add( ThePSSRecord );
  875.   end;
  876.   CCInetCCForm.ComboBox2.Clear;
  877.   CCInetCCForm.ComboBox3.Clear;
  878.   { Add the new info }
  879.   for Counter_1 := 0 to TheWorkingCPSL.Count - 1 do
  880.   begin
  881.     CCINetCCForm.ComboBox2.Items.Add( PConnectionsRecord(
  882.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  883.     CCINetCCForm.ComboBox3.Items.Add( PConnectionsRecord(
  884.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  885.   end;
  886.   CCINetCCForm.ComboBox2.ItemIndex := 0;
  887.   CCINetCCForm.ComboBox3.ItemIndex := 0;
  888. end;
  889.  
  890. procedure TCCINetCCForm.SaveEMailCorrespondentsFile;
  891. var ThePSSRecord : PConnectionsRecord; { The TC Record pointer   }
  892.     PSSLName     : String;             { POP3SMTP Site List filename }
  893.     Counter_1    : Integer;            { Loop counter           }
  894. begin
  895.   { Set up the file name }
  896.   PSSLName := MailPath + '\PSCORRSP.TCR';
  897.   { Assign the file }
  898.   AssignFile( TheEMailCorrespondentsFile , PSSLName );
  899.   { Rewrite it }
  900.   Rewrite( TheEMailCorrespondentsFile );
  901.   { run the list through the procedure }
  902.   for Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  903.   begin
  904.     { get the record from the list }
  905.     ThePSSRecord :=
  906.      PConnectionsRecord( TheCorrespondentsList.Items[ Counter_1 ] );
  907.     { Do the seek/write }
  908.     Seek( TheEMailCorrespondentsFile , Counter_1 );
  909.     Write( TheEMailCorrespondentsFile , ThePSSRecord^ );
  910.     { free the record }
  911.     Dispose( ThePSSRecord );
  912.   end;
  913.   { Close the file }
  914.   CloseFile( TheEMailCorrespondentsFile );
  915.   { Free the list pointers }
  916.   TheCorrespondentsList.Free;
  917.   for Counter_1 := 0 to TheWorkingCPSL.Count - 1 do
  918.   begin
  919.     ThePSSRecord := PConnectionsRecord( TheWorkingCPSL.Items[ Counter_1 ] );
  920.     Dispose( ThePSSRecord );
  921.   end;
  922.   TheWorkingCPSL.Free;
  923. end;
  924.  
  925. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  926. procedure TCCINetCCForm.SetupEMailServerStatus;
  927. begin
  928.   { Set up display for main form }
  929.   CCINetCCForm.Tag := 6; { Email Tag }
  930.   CCINetCCForm.Caption := 'CC Internet Command Center -- EMail Mode';
  931.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  932.   CCINetCCForm.EMail2.Enabled := true;
  933.   CCINetCCForm.EMail1.Enabled := false;
  934.   CCINetCCForm.UsenetNws1.Enabled := false;
  935.   CCINetCCForm.FTP1.Enabled := false;
  936.   CCINetCCForm.Label1.Caption := 'Mail Server:';
  937.   CCINetCCForm.Button1.Caption := 'New Mail';
  938.   CCINetCCForm.Label4.Caption := 'Mailboxes';
  939.   CCINetCCForm.Label5.Caption := 'Messages';
  940. end;
  941.  
  942. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  943. procedure TCCINetCCForm.SetupMailboxLists;
  944. var TheEMMRecord : PEMailMessageRecord; {  }
  945.     Counter_1 ,
  946.     Counter_2    : Integer;             {  }
  947.     EMMFileName  : String;              {  }
  948.     WorkingList  : TList;
  949. begin
  950.   { Abort if no server to select }
  951.   if ComboBox1.ItemIndex = -1 then exit;
  952.   { Get number of server in list }
  953.   WhichServer := ComboBox1.ItemIndex;
  954.   { Load in mailbox data }
  955.   LoadEmailMailboxFile( WhichServer );
  956.   { Load in Mailbox Records and create storage lists }
  957.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  958.   begin
  959.     EMMFileName := PEMailMailboxRecord(
  960.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  961.     if FileExists( MailPath + '\' + EMMFileName ) then
  962.     begin
  963.       WorkingList := TList.Create;
  964.       AssignFile( TheEMailMessagesFile , EMMFileName );
  965.       Reset( TheEMailMessagesFile );
  966.       for Counter_2 := 0 to FileSize( TheEMailMessagesFile ) - 1 do
  967.       begin
  968.         New( TheEMMRecord );
  969.         Seek( TheEMailMessagesFile , Counter_2 );
  970.         Read( TheEMailMessagesFile , TheEMMRecord^ );
  971.         WorkingList.Add( TheEMMRecord );
  972.       end;
  973.       CloseFile( TheEMailMessagesFile );
  974.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  975.        Longint( WorkingList );
  976.     end
  977.     else
  978.     begin
  979.       WorkingList := TList.Create;
  980.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  981.        Longint( WorkingList );
  982.     end;
  983.   end;
  984. end;
  985.  
  986. { This procedure populates LB2 with article subjects for any }
  987. { available articles for a given newsgroup.                  }
  988. procedure TCCINetCCForm.PopulateLB2WithMessageHeaders;
  989. var Counter_1    : Integer;
  990.     TheEMMRecord : PEMailMessageRecord;
  991.     TempString   : String;
  992. begin
  993.   { Clear target list box }
  994.   ListBox2.Clear;
  995.   for Counter_1 := 0 to TheMBMessagesList.Count - 1 do
  996.   begin
  997.     TheEMMRecord :=
  998.      PEMailMessageRecord( TheMBMessagesList.Items[ Counter_1 ] );
  999.     TempString := '    [' + IntToStr( Counter_1 + 1 ) + '] ' +
  1000.      TheEMMRecord^.MRMessageSubject;
  1001.     if TheEMMRecord^.MRRead then TempString[ 2 ] := 'R';
  1002.     if TheEMMRecord^.MRSent then TempString[ 2 ] := 'S';
  1003.     if TheEMMRecord^.MRMessageSender = 'DELETE ME' then TempString[ 3 ] := 'T';
  1004.     ListBox2.Items.Add( TempString );
  1005.   end;
  1006. end;
  1007.  
  1008. { This procedure swaps in the list of subscribed newsgroups to LB1 }
  1009. { and calls another procedure to populate LB2 with any available   }
  1010. { articles for the newsgroup.                                      }
  1011. procedure TCCINetCCForm.SetupEMailListboxes;
  1012. var Counter_1   : Integer;
  1013.     TempString  : String;
  1014.     TheMBRecord : PEMailMailboxRecord;
  1015. begin
  1016.   ListBox1.Clear;
  1017.   ListBox1.Tag := 6;
  1018.   ListBox2.Tag := 6;
  1019.   Label4.Caption := 'Mailboxes';
  1020.   Label5.Caption := 'Messages';
  1021.   if TheEMailMailboxList.Count = 0 then
  1022.   begin
  1023.     ListBox2.Clear;
  1024.     exit;
  1025.   end;
  1026.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  1027.   begin
  1028.     TheMBRecord := PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] );
  1029.     TempString := TheMBRecord^.MBName;
  1030.     if TheMBRecord^.MBUnSentTotal > 0 then TempString := TempString + ' {' +
  1031.      IntToStr( TheMBRecord^.MBUnSentTotal ) + ' Queued}' else
  1032.      if TheMBRecord^.MBUnReadTotal > 0 then TempString := TempString +
  1033.        ' {' + IntToStr( TheMBRecord^.MBUnReadTotal ) + ' New}';
  1034.     TempString := TempString + '{' + IntToStr( TheMBRecord^.MBTotal ) + ' Stored}';
  1035.     ListBox1.Items.Add( TempString );
  1036.   end;
  1037.   TheMBRecord := PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] );
  1038.   TheMBMessagesList := TList( TheMBRecord^.MBLTag );
  1039.   PopulateLB2WithMessageHeaders;
  1040.   Label1.Caption := 'MailBox:';
  1041.   Button1.Caption := 'New Mail';
  1042. end;
  1043.  
  1044. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1045. procedure TCCINetCCForm.SetupEMailServersInfoDisplay;
  1046. var Counter_1  : Integer;            { Loop counter        }
  1047. begin
  1048.   { Set tag for POP3SMTP stuff }
  1049.   CCICInfoDlg.Tag := 6; { EMail Tag -- servers }
  1050.   { set up caption of main label }
  1051.   CCICInfoDlg.Label2.Caption := 'EMail Server Sites';
  1052.   { hide outline panel }
  1053.   CCICInfoDlg.Panel6.Top := 200;
  1054.   CCICInfoDlg.panel6.Height := 144;
  1055.   CCICInfoDlg.Panel6.Visible := false;
  1056.   CCICInfoDlg.Panel5.Visible := true;
  1057.   CCICInfoDlg.Panel8.Visible := true;
  1058.   CCICInfoDlg.Panel9.Visible := true;
  1059.   { clear the list box }
  1060.   CCICInfoDlg.ListBox1.Visible := false;
  1061.   CCICInfoDlg.ListBox2.Clear;
  1062.   CCINetCCForm.ComboBox1.Clear;
  1063.   { add profile strings to the list box }
  1064.   for Counter_1 := 0 to TheEMailServerList.Count - 1 do
  1065.   begin
  1066.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  1067.      TheEMailServerList.Items[ Counter_1 ] )^.CProfile );
  1068.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  1069.      TheEMailServerList.Items[ Counter_1 ] )^.CProfile );
  1070.   end;
  1071.   { Set up caption of special button }
  1072.   CCICInfoDlg.Button1.Visible := false;
  1073.   { Start with top record }
  1074.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1075.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  1076.   { put in data from top record and reset captions }
  1077.   with PConnectionsRecord( TheEMailServerList.Items[ 0 ] )^ do
  1078.   begin
  1079.     with CCICInfoDlg do
  1080.     begin
  1081.       Edit1.Text := CProfile;
  1082.       Panel2.Caption := '            Name:';
  1083.       Edit2.Text := CIPAddress;
  1084.       Panel3.Caption := '     IP Address:';
  1085.       Edit3.Text := CUserName;
  1086.       Panel5.Caption := '    User Name:';
  1087.       CurrentEMRealPWString := CPassword;
  1088.       case EMPasswordControlVector of
  1089.         1 : Edit4.Text := CPassword;
  1090.         2 : Edit4.Text := '**********';
  1091.       end;
  1092.       Panel8.Caption := '      Password:';
  1093.       Edit5.Text := CStartDir;
  1094.       Panel9.Caption := '    EMail Address:';
  1095.     end;
  1096.   end;
  1097. end;
  1098.  
  1099. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1100. procedure TCCINetCCForm.SetupEMailMailboxInfoDisplay;
  1101. var Counter_1      : Integer;
  1102.     TheWorkingList : TList;
  1103. begin
  1104.   { Set tag for POP3SMTP stuff }
  1105.   CCICInfoDlg.Tag := 7; { EMail Tag -- mailboxes }
  1106.   { set up caption of main label }
  1107.   CCICInfoDlg.Label2.Caption := 'Mailboxes';
  1108.   { hide outline panel }
  1109.   CCICInfoDlg.Panel6.Visible := true;
  1110.   CCICInfoDlg.Panel6.Top := 40;
  1111.   CCICInfoDlg.Panel6.Height := 304;
  1112.   CCICInfoDlg.Label1.Caption := 'Saved Messages';
  1113.   CCICInfoDlg.Panel3.Visible := false;
  1114.   CCICInfoDlg.Panel5.Visible := false;
  1115.   CCICInfoDlg.Panel8.Visible := false;
  1116.   CCICInfoDlg.Panel9.Visible := false;
  1117.   { clear the list box }
  1118.   CCICInfoDlg.ListBox1.Visible := true;
  1119.   CCICInfoDlg.ListBox1.MultiSelect := true;
  1120.   CCICInfoDlg.ListBox1.ExtendedSelect := true;
  1121.   CCICInfoDlg.ListBox2.Clear;
  1122.   CCICInfoDlg.ListBox1.Clear;
  1123.   { add profile strings to the list box }
  1124.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  1125.   begin
  1126.     CCICInfoDlg.ListBox2.Items.Add( PEMailMailboxRecord(
  1127.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBName );
  1128.   end;
  1129.   { Set up caption of special button }
  1130.   CCICInfoDlg.Button1.Visible := true;
  1131.   CCICInfoDlg.Button1.Caption := 'XFer on Click';
  1132.   { Start with top record }
  1133.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1134.   { put in data from top record and reset captions }
  1135.   with PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] )^ do
  1136.   begin
  1137.     with CCICInfoDlg do
  1138.     begin
  1139.       Edit1.Text := MBName;
  1140.       Panel2.Caption := 'MB Name:';
  1141.       TheWorkingList := TList( MBLTag );
  1142.       if TheWorkingList.Count > 0 then
  1143.       begin
  1144.         ListBox1.Clear;
  1145.         for Counter_1 := 0 to TheWorkingList.Count - 1 do
  1146.         begin
  1147.           ListBox1.Items.Add( PEMailMessageRecord(
  1148.            TheWorkingList.Items[ Counter_1 ] )^.MRMessageSubject );
  1149.         end;
  1150.         Listbox1.ItemIndex := 0;
  1151.       end;
  1152.     end;
  1153.   end;
  1154. end;
  1155.  
  1156. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1157. procedure TCCINetCCForm.SetupEMailCorrespondentsInfoDisplay;
  1158. var Counter_1  : Integer;            { Loop counter        }
  1159. begin
  1160.   { Set tag for POP3SMTP stuff }
  1161.   CCICInfoDlg.Tag := 8; { EMail Tag -- correspondents }
  1162.   { set up caption of main label }
  1163.   CCICInfoDlg.Label2.Caption := 'Correspondents';
  1164.   { hide outline panel }
  1165.   CCICInfoDlg.Panel3.Visible := true;
  1166.   CCICInfoDlg.Panel6.Visible := false;
  1167.   CCICInfoDlg.Panel5.Visible := false;
  1168.   CCICInfoDlg.Panel8.Visible := false;
  1169.   CCICInfoDlg.Panel9.Visible := false;
  1170.   CCICInfoDlg.ListBox1.Visible := false;
  1171.   { clear the list box }
  1172.   CCICInfoDlg.ListBox2.Clear;
  1173.   { add profile strings to the list box }
  1174.   for Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  1175.   begin
  1176.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  1177.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  1178.   end;
  1179.   { Set up caption of special button }
  1180.   CCICInfoDlg.Button1.Visible := false;
  1181.   { Start with top record }
  1182.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1183.   { put in data from top record and reset captions }
  1184.   with PConnectionsRecord( TheCorrespondentsList.Items[ 0 ] )^ do
  1185.   begin
  1186.     with CCICInfoDlg do
  1187.     begin
  1188.       Edit1.Text := CProfile;
  1189.       Panel2.Caption := '            Name:';
  1190.       Edit2.Text := CIPAddress;
  1191.       Panel3.Caption := 'EMail Address:';
  1192.     end;
  1193.   end;
  1194. end;
  1195.  
  1196. procedure TCCINetCCForm.EnablePOP3SMTPMenus;
  1197. begin
  1198.   Button1.Caption := 'New Mail';
  1199.   CheckMail1.Enabled := true;
  1200.   CreateNewMessage1.Enabled := true;
  1201.   ReplyToCurrentMessage1.Enabled := true;
  1202.   SendCurrentMessage1.Enabled := true;
  1203.   SendQueue1.Enabled := true;
  1204.   MailServers1.Enabled := true;
  1205.   MailBoxes1.Enabled := true;
  1206.   Correspondents1.Enabled := true;
  1207.   TrashMarkedMessages1.Enabled := true;
  1208.   EmptyTrash1.Enabled := true;
  1209. end;
  1210.  
  1211. procedure TCCINetCCForm.DisablePOP3SMTPMenus;
  1212. begin
  1213.   CheckMail1.Enabled := False;
  1214.   CreateNewMessage1.Enabled := False;
  1215.   ReplyToCurrentMessage1.Enabled := False;
  1216.   SendCurrentMessage1.Enabled := False;
  1217.   SendQueue1.Enabled := False;
  1218.   MailServers1.Enabled := False;
  1219.   MailBoxes1.Enabled := False;
  1220.   Correspondents1.Enabled := False;
  1221.   TrashMarkedMessages1.Enabled := False;
  1222.   EmptyTrash1.Enabled := False;
  1223.   EMail1.Enabled := true;
  1224.   FTP1.Enabled := true;
  1225.   UseNetNws1.Enabled := true;
  1226.   IPAddress1.Enabled := true;
  1227.   EMail2.Enabled := false;
  1228. end;
  1229.  
  1230. { This is the FTP component constructor; it creates 2 sockets }
  1231. constructor TFTPComponent.Create( AOwner : TComponent );
  1232. begin
  1233.   { do inherited create }
  1234.   inherited Create( AOwner );
  1235.   { Create sockets, put in their parents, and error procs }
  1236.   Socket1 := TCCSocket.Create( Self );
  1237.   Socket1.Parent := Self;
  1238.   Socket1.OnErrorOccurred := FTPSocketsErrorOccurred;
  1239.   Socket2 := TCCSocket.Create( Self );
  1240.   Socket2.Parent := Self;
  1241.   Socket2.OnErrorOccurred := FTPSocketsErrorOccurred;
  1242.   { Set up booleans }
  1243.   Connection_Established := false;
  1244.   FTPCommandInProgress := false;
  1245. end;
  1246.  
  1247. { This is the FTP component destructor; it frees 2 sockets }
  1248. destructor TFTPComponent.Destroy;
  1249. begin
  1250.   { Free the sockets }
  1251.   Socket1.Free;
  1252.   Socket2.Free;
  1253.   { and call inherited }
  1254.   inherited Destroy;
  1255. end;
  1256.  
  1257. function TFTPComponent.GetShortPathname( TheString : String ) : String;
  1258. var HoldingString : String;
  1259. begin
  1260.   HoldingString := Copy( TheString , 1 , 3 );
  1261.   HoldingString := HoldingString + '..\' + ExtractFileName( TheString );
  1262.   Result := HoldingString;
  1263. end;
  1264.  
  1265. function TFTPComponent.StripBrackets( TheString : String ) : String;
  1266. var HoldingString : String;
  1267.     HoldingPosition : Integer;
  1268. begin
  1269.   HoldingPosition := Pos( '[' , TheString );
  1270.   if HoldingPosition = 0 then
  1271.   begin
  1272.     Result := TheString;
  1273.     exit;
  1274.   end
  1275.   else
  1276.   begin
  1277.     HoldingString := Copy( TheString , HoldingPosition + 1 , 255 );
  1278.     HoldingPosition := Pos( ']' , HoldingString );
  1279.     if HoldingPosition = 0 then
  1280.     begin
  1281.       Result := HoldingString;
  1282.       exit;
  1283.     end
  1284.     else
  1285.     begin
  1286.       HoldingString := Copy( HoldingString , 1 , HoldingPosition - 1 );
  1287.       Result := HoldingString;
  1288.       exit;
  1289.     end;
  1290.   end;
  1291. end;
  1292.  
  1293. { This function takes a UNIX filespec and turns it into a Win16 filename }
  1294. function TFTPComponent.GetWin16FileName( InputName : String ) : String;
  1295. var WorkingString ,
  1296.     HoldingString   : String; { Holding string }
  1297. begin
  1298.   WorkingString := ExtractFileExt( InputName );
  1299.   if WorkingString = '' then
  1300.   begin
  1301.     if Length( InputName ) > 8 then
  1302.      WorkingString := Copy( InputName , 1 , 8 ) else
  1303.       WorkingString := InputName;
  1304.   end
  1305.   else
  1306.   begin
  1307.     if Length( WorkingString ) > 4 then
  1308.      WorkingString := Copy( WorkingString , 1 , 4 );
  1309.     HoldingString :=
  1310.      Copy( InputName , 1 , Pos( WorkingString , InputName ) - 1 );
  1311.     if Length( HoldingString ) > 8 then
  1312.      HoldingString := Copy( HoldingString , 1 , 8 );
  1313.     if HoldingString = '' then
  1314.     begin
  1315.       { Dot file }
  1316.       HoldingString := Copy( InputName , 2 , 255 ) + '.TXT';
  1317.       WorkingString := HoldingString;
  1318.     end
  1319.     else WorkingString := HoldingString + WorkingString;
  1320.   end;
  1321.   Result := WorkingString;
  1322. end;
  1323.  
  1324. { This sends a local file in binary mode to the remote server }
  1325. procedure TFTPComponent.SendBinaryLocalFile( LocalName : String );
  1326. var TheReturnString : String;  { Internal string holder }
  1327.     TheResult       : Integer; { Internal int holder    }
  1328.     Through         : Boolean;
  1329.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1330.     OutputFileHandle : Integer;
  1331.     TotalBytesSent ,
  1332.     BytesRead ,
  1333.     FileToSendSize    : Longint;
  1334.     CopyBuffer       : array[ 0 .. 255 ] of char absolute TheReturnString;
  1335. begin
  1336.   LocalName := ExpandFileName( LocalName );
  1337.   StrPCopy( FileNamePChar , LocalName );
  1338.   OutputFileHandle := _lopen( FileNamePChar , 0 );
  1339.   if OutputFileHandle = -1 then
  1340.   begin
  1341.     MessageDlg( 'Cannot Open local file ' + LocalName ,
  1342.      mtError , [mbOK] , 0 );
  1343.     exit;
  1344.   end;
  1345.   FileToSendSize := _llseek( OutputFileHandle , 0 , 2 );
  1346.   _llseek( OutputFileHandle , 0 , 0 );
  1347.   TheReturnString :=
  1348.    DoCStyleFormat( 'TYPE I' ,
  1349.     [ nil ] );
  1350.   { Put result in progress and status line }
  1351.   AddProgressText( TheReturnString );
  1352.   ShowProgressText( TheReturnString );
  1353.   { Send Password sequence }
  1354.   TheResult := PerformFTPCommand( 'TYPE I',
  1355.                                   [ nil ] );
  1356.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1357.   begin
  1358.     FTPCommandInProgress := false;
  1359.     exit;
  1360.   end;
  1361.   repeat
  1362.     TheResult := GetFTPServerResponse( TheReturnString );
  1363.     { Put result in progress and status line }
  1364.     AddProgressText( TheReturnString );
  1365.     ShowProgressText( TheReturnString );
  1366.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1367.   FTPCommandInProgress := false;
  1368.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1369.   begin
  1370.     { Do clever C formatting trick }
  1371.     TheReturnString :=
  1372.      DoCStyleFormat( 'FTP File Send Failed!' ,
  1373.       [ nil ] );
  1374.     { Put result in progress and status line }
  1375.     AddProgressText( TheReturnString );
  1376.     ShowProgressErrorText( TheReturnString );
  1377.     { leave }
  1378.     exit;
  1379.   end
  1380.   else
  1381.   begin
  1382.     { Set up socket 2 for listening }
  1383.     Socket2.AsynchMode := False;
  1384.     Socket2.NonAsynchTimeoutValue := 60;
  1385.     { do a listen and send command to server that this is receipt socket }
  1386.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1387.     begin
  1388.       Socket2.CCSockCancelListen;
  1389.       exit;
  1390.     end;
  1391.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1392.     TheReturnString :=
  1393.      DoCStyleFormat( 'STOR %s' ,
  1394.       [ ExtractFileName( LocalName ) ] );
  1395.     { Put result in progress and status line }
  1396.     AddProgressText( TheReturnString );
  1397.     ShowProgressText( TheReturnString );
  1398.     TheResult := PerformFTPCommand( 'STOR %s' , [ ExtractFileName( LocalName ) ] );
  1399.     GetFTPServerResponse( TheReturnString );
  1400.     AddProgressText( TheReturnString );
  1401.     ShowProgressText( TheReturnString );
  1402.     Socket1.NonAsynchTimeoutValue := 30;
  1403.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1404.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1405.     begin
  1406.       TheReturnString :=
  1407.        DoCStyleFormat( 'Could not create remote file!' ,
  1408.         [ nil ] );
  1409.       { Put result in progress and status line }
  1410.       AddProgressText( TheReturnString );
  1411.       ShowProgressErrorText( TheReturnString );
  1412.       Socket2.CCSockCancelListen;
  1413.       exit;
  1414.     end;
  1415.     Socket2.CCSockAccept;
  1416.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1417.     begin
  1418.       TheReturnString :=
  1419.        DoCStyleFormat( 'Could not establish send socket!' ,
  1420.         [ nil ] );
  1421.       { Put result in progress and status line }
  1422.       AddProgressText( TheReturnString );
  1423.       ShowProgressErrorText( TheReturnString );
  1424.       exit;
  1425.     end;
  1426.     Through := false;
  1427.     TotalBytesSent := 0;
  1428.     BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1429.     repeat
  1430.       if BytesRead = 0 then Through := true;
  1431.       if BytesRead > 0 then
  1432.       begin
  1433.         CopyBuffer[ 0 ] := Chr( BytesRead );
  1434.         Socket2.StringData := TheReturnString;
  1435.         TotalBytesSent := TotalBytesSent + BytesRead;
  1436.         UpdateGauge( TotalBytesSent , FileToSendSize );
  1437.         BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1438.         if BytesRead = -1 then
  1439.         begin
  1440.           MessageDlg( 'File Read Error on ' + LocalName , mtError , [mbOK] , 0 );
  1441.           GlobalAbortedFlag := True;
  1442.         end;
  1443.       end;
  1444.       if GlobalAbortedFlag then
  1445.       begin
  1446.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1447.         repeat
  1448.           TheResult := GetFTPServerResponse( TheReturnString );
  1449.           { Put result in progress and status line }
  1450.           AddProgressText( TheReturnString );
  1451.           ShowProgressText( TheReturnString );
  1452.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1453.         exit;
  1454.       end;
  1455.     until Through;
  1456.     FTPCommandInProgress := false;
  1457.     { cancel listening on second socket and close it }
  1458.     Socket2.CCSockCancelListen;
  1459.     Socket2.CCSockClose;
  1460.     TheReturnString := 'Transfer Succeeded' + #13#10;
  1461.     AddProgressText( TheReturnString );
  1462.     ShowProgressText( TheReturnString );
  1463.     FTPCommandInProgress := false;
  1464.     PerformFTPCommand( 'TYPE A',
  1465.                                     [ nil ] );
  1466.     Through := false;
  1467.     repeat
  1468.       GetFTPServerResponse( TheReturnString );
  1469.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1470.        Through := true;
  1471.       { Put result in progress and status line }
  1472.       AddProgressText( TheReturnString );
  1473.       ShowProgressText( TheReturnString );
  1474.     until (( GlobalAbortedFlag ) or Through );
  1475.   end;
  1476.   _lclose( OutputFileHandle );
  1477.   FTPCommandInProgress := false;
  1478. end;
  1479.  
  1480. { This sends a local file in ascii mode to remote server }
  1481. procedure TFTPComponent.SendASCIILocalFile( LocalName : String );
  1482. var TheReturnString : String;  { Internal string holder }
  1483.     TheResult       : Integer; { Internal int holder    }
  1484.     Through         : Boolean;
  1485.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1486.     OutputFileHandle : Integer;
  1487.     TotalBytesSent ,
  1488.     BytesRead ,
  1489.     FileToSendSize    : Longint;
  1490.     CopyBuffer       : array[ 0 .. 255 ] of char absolute TheReturnString;
  1491. begin
  1492.   LocalName := ExpandFileName( LocalName );
  1493.   StrPCopy( FileNamePChar , LocalName );
  1494.   OutputFileHandle := _lopen( FileNamePChar , 0 );
  1495.   if OutputFileHandle = -1 then
  1496.   begin
  1497.     MessageDlg( 'Cannot Open local file ' + LocalName ,
  1498.      mtError , [mbOK] , 0 );
  1499.     exit;
  1500.   end;
  1501.   FileToSendSize := _llseek( OutputFileHandle , 0 , 2 );
  1502.   _llseek( OutputFileHandle , 0 , 0 );
  1503.   TheReturnString :=
  1504.    DoCStyleFormat( 'TYPE A' ,
  1505.     [ nil ] );
  1506.   { Put result in progress and status line }
  1507.   AddProgressText( TheReturnString );
  1508.   ShowProgressText( TheReturnString );
  1509.   { Send Password sequence }
  1510.   TheResult := PerformFTPCommand( 'TYPE A',
  1511.                                   [ nil ] );
  1512.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1513.   begin
  1514.     FTPCommandInProgress := false;
  1515.     exit;
  1516.   end;
  1517.   repeat
  1518.     TheResult := GetFTPServerResponse( TheReturnString );
  1519.     { Put result in progress and status line }
  1520.     AddProgressText( TheReturnString );
  1521.     ShowProgressText( TheReturnString );
  1522.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1523.   FTPCommandInProgress := false;
  1524.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1525.   begin
  1526.     { Do clever C formatting trick }
  1527.     TheReturnString :=
  1528.      DoCStyleFormat( 'FTP File Send Failed!' ,
  1529.       [ nil ] );
  1530.     { Put result in progress and status line }
  1531.     AddProgressText( TheReturnString );
  1532.     ShowProgressErrorText( TheReturnString );
  1533.     { leave }
  1534.     exit;
  1535.   end
  1536.   else
  1537.   begin
  1538.     { Set up socket 2 for listening }
  1539.     Socket2.AsynchMode := False;
  1540.     Socket2.NonAsynchTimeoutValue := 60;
  1541.     { do a listen and send command to server that this is receipt socket }
  1542.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1543.     begin
  1544.       Socket2.CCSockCancelListen;
  1545.       exit;
  1546.     end;
  1547.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1548.     TheReturnString :=
  1549.      DoCStyleFormat( 'STOR %s' ,
  1550.       [ ExtractFileName( LocalName ) ] );
  1551.     { Put result in progress and status line }
  1552.     AddProgressText( TheReturnString );
  1553.     ShowProgressText( TheReturnString );
  1554.     TheResult := PerformFTPCommand( 'STOR %s' , [ ExtractFileName( LocalName )]);
  1555.     GetFTPServerResponse( TheReturnString );
  1556.     AddProgressText( TheReturnString );
  1557.     ShowProgressText( TheReturnString );
  1558.     Socket1.NonAsynchTimeoutValue := 30;
  1559.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1560.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1561.     begin
  1562.       TheReturnString :=
  1563.        DoCStyleFormat( 'Could not create remote file!' ,
  1564.         [ nil ] );
  1565.       { Put result in progress and status line }
  1566.       AddProgressText( TheReturnString );
  1567.       ShowProgressErrorText( TheReturnString );
  1568.       Socket2.CCSockCancelListen;
  1569.       exit;
  1570.     end;
  1571.     Socket2.CCSockAccept;
  1572.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1573.     begin
  1574.       TheReturnString :=
  1575.        DoCStyleFormat( 'Could not establish send socket!' ,
  1576.         [ nil ] );
  1577.       { Put result in progress and status line }
  1578.       AddProgressText( TheReturnString );
  1579.       ShowProgressErrorText( TheReturnString );
  1580.       exit;
  1581.     end;
  1582.     Through := false;
  1583.     TotalBytesSent := 0;
  1584.     BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1585.     repeat
  1586.       if BytesRead = 0 then Through := true;
  1587.       if BytesRead > 0 then
  1588.       begin
  1589.         CopyBuffer[ 0 ] := Chr( BytesRead );
  1590.         Socket2.StringData := TheReturnString;
  1591.         TotalBytesSent := TotalBytesSent + BytesRead;
  1592.         UpdateGauge( TotalBytesSent , FileToSendSize );
  1593.         BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1594.         if BytesRead = -1 then
  1595.         begin
  1596.           MessageDlg( 'File Read Error on ' + LocalName , mtError , [mbOK] , 0 );
  1597.           GlobalAbortedFlag := True;
  1598.         end;
  1599.       end;
  1600.       if GlobalAbortedFlag then
  1601.       begin
  1602.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1603.         repeat
  1604.           TheResult := GetFTPServerResponse( TheReturnString );
  1605.           { Put result in progress and status line }
  1606.           AddProgressText( TheReturnString );
  1607.           ShowProgressText( TheReturnString );
  1608.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1609.         exit;
  1610.       end;
  1611.     until Through;
  1612.     { cancel listening on second socket and close it }
  1613.     Socket2.CCSockCancelListen;
  1614.     Socket2.CCSockClose;
  1615.     TheReturnString := 'Transfer Succeeded' + #13#10;
  1616.     AddProgressText( TheReturnString );
  1617.     ShowProgressText( TheReturnString );
  1618.     FTPCommandInProgress := false;
  1619.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1620.     Through := false;
  1621.     repeat
  1622.       GetFTPServerResponse( TheReturnString );
  1623.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1624.        Through := true;
  1625.       { Put result in progress and status line }
  1626.       AddProgressText( TheReturnString );
  1627.       ShowProgressText( TheReturnString );
  1628.     until (( GlobalAbortedFlag ) or Through );
  1629.   end;
  1630.   _lclose( OutputFileHandle );
  1631.   FTPCommandInProgress := false;
  1632. end;
  1633.  
  1634. { This function strips out the FTP response for bytes to send }
  1635. function TFTPComponent.GetTotalBytesToReceive( TheString : String ) : Longint;
  1636. var
  1637.   LeftPosition ,
  1638.   RightPosition  : integer;
  1639.   TempString     : string;
  1640. begin
  1641.   LeftPosition := Pos( '(' , TheString );
  1642.   TempString := Copy( TheString ,
  1643.                       LeftPosition + 1 , 255 );
  1644.   RightPosition := Pos( ' ' , TempString );
  1645.   if (( LeftPosition = 0 ) or ( RightPosition = 0 )) then
  1646.   begin
  1647.     Result := 0;
  1648.     exit;
  1649.   end;
  1650.   if RightPosition <> 0 then
  1651.     TempString := Copy( TempString , 1 , RightPosition - 1  );
  1652.   try
  1653.     Result := StrToInt( TempString );
  1654.   except
  1655.     on EConvertError do Result := 0;
  1656.   end;
  1657. end;
  1658.  
  1659. procedure TFTPComponent.UpdateGauge( BytesFinished , TotalToHandle : longint );
  1660. begin
  1661.   CCInetCCForm.UpdateGauge( BytesFinished , TotalToHandle );
  1662. end;
  1663.  
  1664. { This sends FTP progress text to the Inet form }
  1665. procedure TFTPComponent.AddProgressText( WhatText : String );
  1666. begin
  1667.   CCInetCCForm.AddProgressText( WhatText );
  1668. end;
  1669.  
  1670. { This sends FTP progress text to the Inet form }
  1671. procedure TFTPComponent.ShowProgressText( WhatText : String );
  1672. begin
  1673.   CCInetCCForm.ShowProgressText( WhatText );
  1674. end;
  1675.  
  1676. { This procedure receives a binary remote file }
  1677. procedure TFTPComponent.ReceiveASCIIRemoteFileToMemo( RemoteName : String );
  1678. var TheReturnString : String;  { Internal string holder }
  1679.     TheResult       : Integer; { Internal int holder    }
  1680.     Through         : Boolean;
  1681.     TotalBytesSent ,
  1682.     FileToGetSize    : Longint;
  1683. begin
  1684.   TheReturnString :=
  1685.    DoCStyleFormat( 'TYPE A' ,
  1686.     [ nil ] );
  1687.   { Put result in progress and status line }
  1688.   AddProgressText( TheReturnString );
  1689.   ShowProgressText( TheReturnString );
  1690.   { Send Password sequence }
  1691.   FTPCommandInProgress := false;
  1692.   TheResult := PerformFTPCommand( 'TYPE A',
  1693.                                   [ nil ] );
  1694.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1695.   begin
  1696.     FTPCommandInProgress := false;
  1697.     exit;
  1698.   end;
  1699.   repeat
  1700.     TheResult := GetFTPServerResponse( TheReturnString );
  1701.     { Put result in progress and status line }
  1702.     AddProgressText( TheReturnString );
  1703.     ShowProgressText( TheReturnString );
  1704.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1705.   FTPCommandInProgress := false;
  1706.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1707.   begin
  1708.     { Do clever C formatting trick }
  1709.     TheReturnString :=
  1710.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  1711.       [ nil ] );
  1712.     { Put result in progress and status line }
  1713.     AddProgressText( TheReturnString );
  1714.     ShowProgressErrorText( TheReturnString );
  1715.     { leave }
  1716.     exit;
  1717.   end
  1718.   else
  1719.   begin
  1720.     { Set up socket 2 for listening }
  1721.     Socket2.AsynchMode := False;
  1722.     Socket2.NonAsynchTimeoutValue := 60;
  1723.     { do a listen and send command to server that this is receipt socket }
  1724.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1725.     begin
  1726.       Socket2.CCSockCancelListen;
  1727.       exit;
  1728.     end;
  1729.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1730.     TheReturnString :=
  1731.      DoCStyleFormat( 'RETR %s' ,
  1732.       [ RemoteName ] );
  1733.     { Put result in progress and status line }
  1734.     AddProgressText( TheReturnString );
  1735.     ShowProgressText( TheReturnString );
  1736.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  1737.     GetFTPServerResponse( TheReturnString );
  1738.     AddProgressText( TheReturnString );
  1739.     ShowProgressText( TheReturnString );
  1740.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  1741.     Socket1.NonAsynchTimeoutValue := 30;
  1742.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1743.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1744.     begin
  1745.       TheReturnString :=
  1746.        DoCStyleFormat( 'Could not obtain remote file!' ,
  1747.         [ nil ] );
  1748.       { Put result in progress and status line }
  1749.       AddProgressText( TheReturnString );
  1750.       ShowProgressErrorText( TheReturnString );
  1751.       Socket2.CCSockCancelListen;
  1752.       exit;
  1753.     end;
  1754.     Socket2.CCSockAccept;
  1755.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1756.     begin
  1757.       TheReturnString :=
  1758.        DoCStyleFormat( 'Could not establish receive socket!' ,
  1759.         [ nil ] );
  1760.       { Put result in progress and status line }
  1761.       AddProgressText( TheReturnString );
  1762.       ShowProgressErrorText( TheReturnString );
  1763.       exit;
  1764.     end;
  1765.     Through := false;
  1766.     TotalBytesSent := 0;
  1767.     repeat
  1768.       TheReturnString := Socket2.StringData;
  1769.       if Length( TheReturnString ) = 0 then Through := true;
  1770.       if Length( TheReturnString ) > 0 then
  1771.       begin
  1772.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  1773.         UpdateGauge( TotalBytesSent , FileToGetSize );
  1774.         { Put result in progress and status line }
  1775.         AddProgressText( TheReturnString );
  1776.         ShowProgressText( TheReturnString );
  1777.       end;
  1778.       if GlobalAbortedFlag then
  1779.       begin
  1780.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1781.         repeat
  1782.           TheResult := GetFTPServerResponse( TheReturnString );
  1783.           { Put result in progress and status line }
  1784.           AddProgressText( TheReturnString );
  1785.           ShowProgressText( TheReturnString );
  1786.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1787.         exit;
  1788.       end;
  1789.     until Through;
  1790.     { cancel listening on second socket and close it }
  1791.     Socket2.CCSockCancelListen;
  1792.     Socket2.CCSockClose;
  1793.     FTPCommandInProgress := false;
  1794.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1795.     Through := false;
  1796.     repeat
  1797.       GetFTPServerResponse( TheReturnString );
  1798.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1799.        Through := true;
  1800.       { Put result in progress and status line }
  1801.       AddProgressText( TheReturnString );
  1802.       ShowProgressText( TheReturnString );
  1803.     until (( GlobalAbortedFlag ) or Through );
  1804.   end;
  1805.   FTPCommandInProgress := false;
  1806. end;
  1807.  
  1808. { This procedure receives a binary remote file }
  1809. procedure TFTPComponent.ReceiveASCIIRemoteFile( RemoteName , LocalName : String );
  1810. var TheReturnString : String;  { Internal string holder }
  1811.     TheResult       : Integer; { Internal int holder    }
  1812.     Through         : Boolean;
  1813.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1814.     OutputFileHandle : Integer;
  1815.     TotalBytesSent ,
  1816.     FileToGetSize    : Longint;
  1817.     CopyBuffer       : array[ 0 .. 255 ] of char;
  1818. begin
  1819.   LocalName := ExpandFileName( LocalName );
  1820.   StrPCopy( FileNamePChar , LocalName );
  1821.   OutputFileHandle := _lcreat( FileNamePChar , 0 );
  1822.   if OutputFileHandle = -1 then
  1823.   begin
  1824.     MessageDlg( 'Cannot Create local file ' + LocalName ,
  1825.      mtError , [mbOK] , 0 );
  1826.     exit;
  1827.   end;
  1828.   TheReturnString :=
  1829.    DoCStyleFormat( 'TYPE A' ,
  1830.     [ nil ] );
  1831.   { Put result in progress and status line }
  1832.   AddProgressText( TheReturnString );
  1833.   ShowProgressText( TheReturnString );
  1834.   { Send Password sequence }
  1835.   TheResult := PerformFTPCommand( 'TYPE A',
  1836.                                   [ nil ] );
  1837.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1838.   begin
  1839.     FTPCommandInProgress := false;
  1840.     exit;
  1841.   end;
  1842.   repeat
  1843.     TheResult := GetFTPServerResponse( TheReturnString );
  1844.     { Put result in progress and status line }
  1845.     AddProgressText( TheReturnString );
  1846.     ShowProgressText( TheReturnString );
  1847.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1848.   FTPCommandInProgress := false;
  1849.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1850.   begin
  1851.     { Do clever C formatting trick }
  1852.     TheReturnString :=
  1853.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  1854.       [ nil ] );
  1855.     { Put result in progress and status line }
  1856.     AddProgressText( TheReturnString );
  1857.     ShowProgressErrorText( TheReturnString );
  1858.     { leave }
  1859.     exit;
  1860.   end
  1861.   else
  1862.   begin
  1863.     { Set up socket 2 for listening }
  1864.     Socket2.AsynchMode := False;
  1865.     Socket2.NonAsynchTimeoutValue := 60;
  1866.     { do a listen and send command to server that this is receipt socket }
  1867.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1868.     begin
  1869.       Socket2.CCSockCancelListen;
  1870.       exit;
  1871.     end;
  1872.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1873.     TheReturnString :=
  1874.      DoCStyleFormat( 'RETR %s' ,
  1875.       [ RemoteName ] );
  1876.     { Put result in progress and status line }
  1877.     AddProgressText( TheReturnString );
  1878.     ShowProgressText( TheReturnString );
  1879.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  1880.     GetFTPServerResponse( TheReturnString );
  1881.     AddProgressText( TheReturnString );
  1882.     ShowProgressText( TheReturnString );
  1883.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  1884.     Socket1.NonAsynchTimeoutValue := 30;
  1885.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1886.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1887.     begin
  1888.       TheReturnString :=
  1889.        DoCStyleFormat( 'Could not obtain remote file!' ,
  1890.         [ nil ] );
  1891.       { Put result in progress and status line }
  1892.       AddProgressText( TheReturnString );
  1893.       ShowProgressErrorText( TheReturnString );
  1894.       Socket2.CCSockCancelListen;
  1895.       exit;
  1896.     end;
  1897.     Socket2.CCSockAccept;
  1898.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1899.     begin
  1900.       TheReturnString :=
  1901.        DoCStyleFormat( 'Could not establish receive socket!' ,
  1902.         [ nil ] );
  1903.       { Put result in progress and status line }
  1904.       AddProgressText( TheReturnString );
  1905.       ShowProgressErrorText( TheReturnString );
  1906.       exit;
  1907.     end;
  1908.     Through := false;
  1909.     TotalBytesSent := 0;
  1910.     repeat
  1911.       TheReturnString := Socket2.StringData;
  1912.       if Length( TheReturnString ) = 0 then Through := true;
  1913.       if Length( TheReturnString ) > 0 then
  1914.       begin
  1915.         StrPCopy( CopyBuffer , TheReturnString );
  1916.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  1917.         UpdateGauge( TotalBytesSent , FileToGetSize );
  1918.         if _lwrite( OutputFileHandle , CopyBuffer , Length( TheReturnString ))
  1919.          = -1 then
  1920.         begin
  1921.           MessageDlg( 'File Write Error on ' + LocalName , mtError , [mbOK] , 0 );
  1922.           GlobalAbortedFlag := True;
  1923.         end;
  1924.       end;
  1925.       if GlobalAbortedFlag then
  1926.       begin
  1927.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1928.         repeat
  1929.           TheResult := GetFTPServerResponse( TheReturnString );
  1930.           { Put result in progress and status line }
  1931.           AddProgressText( TheReturnString );
  1932.           ShowProgressText( TheReturnString );
  1933.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1934.         exit;
  1935.       end;
  1936.     until Through;
  1937.     { cancel listening on second socket and close it }
  1938.     Socket2.CCSockCancelListen;
  1939.     Socket2.CCSockClose;
  1940.     FTPCommandInProgress := false;
  1941.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1942.     Through := false;
  1943.     repeat
  1944.       GetFTPServerResponse( TheReturnString );
  1945.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1946.        Through := true;
  1947.       { Put result in progress and status line }
  1948.       AddProgressText( TheReturnString );
  1949.       ShowProgressText( TheReturnString );
  1950.     until (( GlobalAbortedFlag ) or Through );
  1951.   end;
  1952.   _lclose( OutputFileHandle );
  1953.   FTPCommandInProgress := false;
  1954. end;
  1955.  
  1956. { This procedure receives a binary remote file }
  1957. procedure TFTPComponent.ReceiveBinaryRemoteFile( RemoteName , LocalName : String );
  1958. var TheReturnString : String;  { Internal string holder }
  1959.     TheResult       : Integer; { Internal int holder    }
  1960.     Through         : Boolean;
  1961.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1962.     OutputFileHandle : Integer;
  1963.     TotalBytesSent ,
  1964.     FileToGetSize    : Longint;
  1965.     CopyBuffer       : array[ 0 .. 255 ] of char;
  1966. begin
  1967.   LocalName := ExpandFileName( LocalName );
  1968.   StrPCopy( FileNamePChar , LocalName );
  1969.   OutputFileHandle := _lcreat( FileNamePChar , 0 );
  1970.   if OutputFileHandle = -1 then
  1971.   begin
  1972.     MessageDlg( 'Cannot Create local file ' + LocalName ,
  1973.      mtError , [mbOK] , 0 );
  1974.     exit;
  1975.   end;
  1976.   TheReturnString :=
  1977.    DoCStyleFormat( 'TYPE I' ,
  1978.     [ nil ] );
  1979.   { Put result in progress and status line }
  1980.   AddProgressText( TheReturnString );
  1981.   ShowProgressText( TheReturnString );
  1982.   { Send Password sequence }
  1983.   TheResult := PerformFTPCommand( 'TYPE I',
  1984.                                   [ nil ] );
  1985.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1986.   begin
  1987.     FTPCommandInProgress := false;
  1988.     exit;
  1989.   end;
  1990.   repeat
  1991.     TheResult := GetFTPServerResponse( TheReturnString );
  1992.     { Put result in progress and status line }
  1993.     AddProgressText( TheReturnString );
  1994.     ShowProgressText( TheReturnString );
  1995.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1996.   FTPCommandInProgress := false;
  1997.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1998.   begin
  1999.     { Do clever C formatting trick }
  2000.     TheReturnString :=
  2001.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  2002.       [ nil ] );
  2003.     { Put result in progress and status line }
  2004.     AddProgressText( TheReturnString );
  2005.     ShowProgressErrorText( TheReturnString );
  2006.     { leave }
  2007.     exit;
  2008.   end
  2009.   else
  2010.   begin
  2011.     { Set up socket 2 for listening }
  2012.     Socket2.AsynchMode := False;
  2013.     Socket2.NonAsynchTimeoutValue := 60;
  2014.     { do a listen and send command to server that this is receipt socket }
  2015.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  2016.     begin
  2017.       Socket2.CCSockCancelListen;
  2018.       exit;
  2019.     end;
  2020.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  2021.     TheReturnString :=
  2022.      DoCStyleFormat( 'RETR %s' ,
  2023.       [ RemoteName ] );
  2024.     { Put result in progress and status line }
  2025.     AddProgressText( TheReturnString );
  2026.     ShowProgressText( TheReturnString );
  2027.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  2028.     GetFTPServerResponse( TheReturnString );
  2029.     AddProgressText( TheReturnString );
  2030.     ShowProgressText( TheReturnString );
  2031.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  2032.     Socket1.NonAsynchTimeoutValue := 30;
  2033.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  2034.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  2035.     begin
  2036.       TheReturnString :=
  2037.        DoCStyleFormat( 'Could not obtain remote file!' ,
  2038.         [ nil ] );
  2039.       { Put result in progress and status line }
  2040.       AddProgressText( TheReturnString );
  2041.       ShowProgressErrorText( TheReturnString );
  2042.       Socket2.CCSockCancelListen;
  2043.       exit;
  2044.     end;
  2045.     Socket2.CCSockAccept;
  2046.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  2047.     begin
  2048.       TheReturnString :=
  2049.        DoCStyleFormat( 'Could not establish receive socket!' ,
  2050.         [ nil ] );
  2051.       { Put result in progress and status line }
  2052.       AddProgressText( TheReturnString );
  2053.       ShowProgressErrorText( TheReturnString );
  2054.       exit;
  2055.     end;
  2056.     Through := false;
  2057.     TotalBytesSent := 0;
  2058.     repeat
  2059.       TheReturnString := Socket2.StringData;
  2060.       if Length( TheReturnString ) = 0 then Through := true;
  2061.       if Length( TheReturnString ) > 0 then
  2062.       begin
  2063.         StrPCopy( CopyBuffer , TheReturnString );
  2064.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  2065.         UpdateGauge( TotalBytesSent , FileToGetSize );
  2066.         if _lwrite( OutputFileHandle , CopyBuffer , Length( TheReturnString ))
  2067.          = -1 then
  2068.         begin
  2069.           MessageDlg( 'File Write Error on ' + LocalName , mtError , [mbOK] , 0 );
  2070.           GlobalAbortedFlag := True;
  2071.         end;
  2072.       end;
  2073.       if GlobalAbortedFlag then
  2074.       begin
  2075.         Socket1.OutOfBand := 'ABOR'+#13#10;
  2076.         repeat
  2077.           TheResult := GetFTPServerResponse( TheReturnString );
  2078.           { Put result in progress and status line }
  2079.           AddProgressText( TheReturnString );
  2080.           ShowProgressText( TheReturnString );
  2081.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2082.         exit;
  2083.       end;
  2084.     until Through;
  2085.     { cancel listening on second socket and close it }
  2086.     Socket2.CCSockCancelListen;
  2087.     Socket2.CCSockClose;
  2088.     FTPCommandInProgress := false;
  2089.     PerformFTPCommand( 'TYPE A', [ nil ] );
  2090.     Through := false;
  2091.     repeat
  2092.       GetFTPServerResponse( TheReturnString );
  2093.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  2094.        Through := true;
  2095.       { Put result in progress and status line }
  2096.       AddProgressText( TheReturnString );
  2097.       ShowProgressText( TheReturnString );
  2098.     until (( GlobalAbortedFlag ) or Through );
  2099.   end;
  2100.   _lclose( OutputFileHandle );
  2101.   FTPCommandInProgress := false;
  2102. end;
  2103.  
  2104. { This sends FTP progress text to the Inet form }
  2105. procedure TFTPComponent.ShowProgressErrorText( WhatText : String );
  2106. begin
  2107.   CCInetCCForm.ShowProgressErrorText( WhatText );
  2108. end;
  2109.  
  2110. { This is a core function! It performs an FTP command and if no timeout }
  2111. { return a preliminary ok.                                              }
  2112. function TFTPComponent.PerformFTPCommand(
  2113.                  TheCommand        : string;
  2114.            const TheArguments      : array of const ) : Integer;
  2115. var TheBuffer : string; { Text buffer }
  2116. begin
  2117.   { If command in progress send back -1 error }
  2118.   if FTPCommandInProgress then
  2119.   begin
  2120.     Result := -1;
  2121.     exit;
  2122.   end;
  2123.   { Set status variable }
  2124.   FTPCommandInProgress := True;
  2125.   { Set global error code }
  2126.   GlobalErrorCode := 0;
  2127.   { Format output string }
  2128.   TheBuffer := Format( TheCommand , TheArguments );
  2129.   { Preset failure code }
  2130.   Result := TCPIP_STATUS_FATAL_ERROR;
  2131.   { If invalid socket or no connection abort }
  2132.   if ( Socket1.TheSocket = INVALID_SOCKET ) or not Connection_Established then
  2133.    exit;
  2134.   { Send the buffer plus EOL chars }
  2135.   Socket1.StringData := TheBuffer + #13#10;
  2136.   { if abort due to timeout or other error exit }
  2137.   if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2138.   { Otherwise return preliminary code }
  2139.   Result := TCPIP_STATUS_PRELIMINARY;
  2140. end;
  2141.  
  2142. { This function gets up to 255 chars of data plus a return code from FTP serv }
  2143. function TFTPComponent.GetFTPServerResponse(
  2144.           var ResponseString : String ) : integer;
  2145. var
  2146.   { Buffer string for response line }
  2147.   TheBuffer     : string;
  2148.   { Pointer to the response string }
  2149.   BufferPointer : array[0..255] of char absolute TheBuffer;
  2150.   { Character to check for response code }
  2151.   ResponseChar   : char;
  2152.   { Pointers into returned string }
  2153.   TheIndex ,
  2154.   TheLength     : integer;
  2155.   { Control variable }
  2156.   LeftoversInPan ,
  2157.   Finished      : Boolean;
  2158. begin
  2159.   { Preset fatal error }
  2160.   Result := TCPIP_STATUS_FATAL_ERROR;
  2161.   { Start loop control }
  2162.   LeftoversInPan := false;
  2163.   Finished := false;
  2164.   repeat
  2165.     { Do a peek }
  2166.     TheBuffer := Socket1.PeekData;
  2167.     { If timeout or other error exit }
  2168.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2169.     { Find end of line character }
  2170.     TheIndex := Pos( #10 , TheBuffer );
  2171.     if TheIndex = 0 then
  2172.     begin
  2173.       TheIndex := Pos( #13 , TheBuffer );
  2174.       if TheIndex = 0 then
  2175.       begin
  2176.         TheIndex := Pos( #0 , TheBuffer );
  2177.         if TheIndex = 0 then
  2178.         begin
  2179.           TheIndex := Length( TheBuffer );
  2180.           LeftoversInPan := True;
  2181.           LeftoverText := LeftoverText + TheBuffer;
  2182.           LeftoversOnTable := false;
  2183.         end;
  2184.       end;
  2185.     end;
  2186.     { If an end of line then process the line }
  2187.     if TheIndex > 0 then
  2188.     begin
  2189.       { Get length of string }
  2190.       TheLength := TheIndex;
  2191.       { Receive actual data }
  2192.       Socket1.CCSockReceive( Socket1.TheSocket   ,
  2193.                              @BufferPointer[ 1 ] ,
  2194.                              TheLength              );
  2195.       { Abort if timeout or error }
  2196.       if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2197.       { Put in the length byte }
  2198.       BufferPointer[ 0 ] := Chr( TheLength );
  2199.       if LeftOversOnTable then
  2200.       begin
  2201.         LeftOversOnTable := false;
  2202.         ResponseString := LeftoverText + TheBuffer;
  2203.         TheBuffer := ResponseString;
  2204.         LeftoverText := '';
  2205.       end;
  2206.       if LeftoversInPan then
  2207.       begin
  2208.         LeftoversInPan := false;
  2209.         LeftoversOnTable := true;
  2210.       end;
  2211.       { If not a continuation line }
  2212.       if TheBuffer[ 4 ] <> '-' then
  2213.       begin
  2214.         { Get first number character }
  2215.         ResponseChar := TheBuffer[ 1 ];
  2216.         { Get the value of the number from 1 to 5 }
  2217.         if (( ResponseChar >= '1' ) and ( ResponseChar <= '5' )) then
  2218.         begin
  2219.           Finished := true;
  2220.           Result := Ord( ResponseChar ) - 48;
  2221.         end;
  2222.       end
  2223.       else
  2224.       begin
  2225.         { otherwise return preliminary result }
  2226.         Finished := true;
  2227.         Result := TCPIP_STATUS_PRELIMINARY;
  2228.       end;
  2229.     end
  2230.     else
  2231.     begin
  2232.     end;
  2233.   until ( Finished and ( not LeftoversOnTable ));
  2234.   { Return buffer as response string }
  2235.   ResponseString := TheBuffer;
  2236. end;
  2237.  
  2238. { Boilerplate error routine }
  2239. procedure TFTPComponent.FTPSocketsErrorOccurred( Sender     : TObject;
  2240.                                                  ErrorCode  : Integer;
  2241.                                                  TheMessage : String   );
  2242. begin
  2243.   CCInetCCForm.SocketsErrorOccurred( Sender,ErrorCode,TheMessage );
  2244. end;
  2245.  
  2246. { This is the FTP components initial connection routine }
  2247. function TFTPComponent.EstablishConnection(
  2248.           PCRPointer : PConnectionsRecord ) : Boolean;
  2249. var TheReturnString : String;  { Internal string holder }
  2250.     TheResult       : Integer; { Internal int holder    }
  2251. begin
  2252.   { Set default FTP Port value }
  2253.   Socket1.PortName := '21';
  2254.   { Get the ip address from the record }
  2255.   Socket1.IPAddressName := PCRPointer^.CIPAddress;
  2256.   { Set blocking mode }
  2257.   Socket1.AsynchMode := False;
  2258.   { Clear condition variables }
  2259.   GlobalErrorCode := 0;
  2260.   GlobalAbortedFlag := false;
  2261.   { Actually attempt to connect }
  2262.   Socket1.CCSockConnect;
  2263.   { Check if connected }
  2264.   if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 ) or
  2265.       ( Socket1.TheSocket = INVALID_SOCKET )) then
  2266.   begin { Didn't connect; signal error and abort }
  2267.     { Do clever C formatting trick }
  2268.     TheReturnString :=
  2269.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2270.       [ PCRPointer^.CIPAddress ] );
  2271.     { Put result in progress and status line }
  2272.     AddProgressText( TheReturnString );
  2273.     ShowProgressErrorText( TheReturnString );
  2274.     { Signal error }
  2275.     Result := False;
  2276.     { leave }
  2277.     exit;
  2278.   end
  2279.   else
  2280.   begin
  2281.     Connection_Established := true;
  2282.     { Signal successful connection }
  2283.     TheReturnString := DoCStyleFormat(
  2284.       'Connected on Local port: %s with IP: %s',
  2285.       [ Socket1.GetSocketPort( Socket1.TheSocket ),
  2286.         Socket1.GetSocketIPAddress( Socket1.TheSocket )]);
  2287.     { Put result in progress and status line }
  2288.     CCINetCCForm.AddProgressText( TheReturnString );
  2289.     CCINetCCForm.ShowProgressText( TheReturnString );
  2290.     TheReturnString := DoCStyleFormat(
  2291.      'Connected to Remote port: %s with IP: %s',
  2292.       [ Socket1.GetSocketPeerPort( Socket1.TheSocket ),
  2293.         Socket1.GetSocketPeerIPAddress( Socket1.TheSocket )]);
  2294.     { Put result in progress and status line }
  2295.     CCINetCCForm.AddProgressText( TheReturnString );
  2296.     CCINetCCForm.ShowProgressText( TheReturnString );
  2297.     TheReturnString := DoCStyleFormat( 'Successfully connected to %s',
  2298.      [ Socket1.IPAddressName ]);
  2299.     { Put result in progress and status line }
  2300.     CCINetCCForm.AddProgressText( TheReturnString );
  2301.     CCINetCCForm.ShowProgressText( TheReturnString );
  2302.     repeat
  2303.       TheResult := GetFTPServerResponse( TheReturnString );
  2304.       { Put result in progress and status line }
  2305.       AddProgressText( TheReturnString );
  2306.       ShowProgressText( TheReturnString );
  2307.     until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2308.     if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2309.     begin
  2310.       { Do clever C formatting trick }
  2311.       TheReturnString :=
  2312.        DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2313.         [ PCRPointer^.CIPAddress ] );
  2314.       { Put result in progress and status line }
  2315.       AddProgressText( TheReturnString );
  2316.       ShowProgressErrorText( TheReturnString );
  2317.       { Signal error }
  2318.       Result := False;
  2319.       { leave }
  2320.       exit;
  2321.     end
  2322.     else Result := true; { Signal no problem }
  2323.   end;
  2324. end;
  2325.  
  2326. { This is the FTP components USER login routine }
  2327. function TFTPComponent.LoginUser(
  2328.           PCRPointer : PConnectionsRecord ) : Boolean;
  2329. var TheReturnString : String;  { Internal string holder }
  2330.     TheResult       : Integer; { Internal int holder    }
  2331. begin
  2332.   TheReturnString :=
  2333.    DoCStyleFormat( 'USER %s' ,
  2334.     [ PCRPointer^.CUserName ] );
  2335.   { Put result in progress and status line }
  2336.   AddProgressText( TheReturnString );
  2337.   ShowProgressText( TheReturnString );
  2338.   { Begin login sequence with user name }
  2339.   TheResult := PerformFTPCommand( 'USER %s',
  2340.                                   [ PCRPointer^.CUserName ] );
  2341.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2342.   begin
  2343.     FTPCommandInProgress := false;
  2344.     Result := false;
  2345.     exit;
  2346.   end;
  2347.   repeat
  2348.     TheResult := GetFTPServerResponse( TheReturnString );
  2349.     { Put result in progress and status line }
  2350.     AddProgressText( TheReturnString );
  2351.     ShowProgressText( TheReturnString );
  2352.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2353.   FTPCommandInProgress := false;
  2354.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_CONTINUING )) then
  2355.   begin
  2356.     { Do clever C formatting trick }
  2357.     TheReturnString :=
  2358.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2359.       [ PCRPointer^.CIPAddress ] );
  2360.     { Put result in progress and status line }
  2361.     AddProgressText( TheReturnString );
  2362.     ShowProgressErrorText( TheReturnString );
  2363.     { Signal error }
  2364.     Result := False;
  2365.     { leave }
  2366.     exit;
  2367.   end
  2368.   else Result := true; { Signal no problem }
  2369. end;
  2370.  
  2371. function TFTPComponent.DeleteRemoteDirectory( TheDir : String ) : Boolean;
  2372. var TheReturnString : String;  { Internal string holder }
  2373.     TheResult       : Integer; { Internal int holder    }
  2374. begin
  2375.   TheReturnString := DoCStyleFormat( 'RMD %s' ,
  2376.    [ TheDir ] );
  2377.   { Put result in progress and status line }
  2378.   AddProgressText( TheReturnString );
  2379.   ShowProgressText( TheReturnString );
  2380.   { Send Password sequence }
  2381.   TheResult := PerformFTPCommand( 'RMD %s',
  2382.                                   [ TheDir ] );
  2383.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2384.   begin
  2385.     Result := false;
  2386.     FTPCommandInProgress := false;
  2387.     exit;
  2388.   end;
  2389.   repeat
  2390.     TheResult := GetFTPServerResponse( TheReturnString );
  2391.     { Put result in progress and status line }
  2392.     AddProgressText( TheReturnString );
  2393.     ShowProgressText( TheReturnString );
  2394.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2395.   FTPCommandInProgress := false;
  2396.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2397.   begin
  2398.     { Do clever C formatting trick }
  2399.     TheReturnString :=
  2400.      DoCStyleFormat( 'Delete Directory %s Failed!' ,
  2401.       [ TheDir ] );
  2402.     { Put result in progress and status line }
  2403.     AddProgressText( TheReturnString );
  2404.     ShowProgressErrorText( TheReturnString );
  2405.     { Signal error }
  2406.     Result := False;
  2407.     { leave }
  2408.     exit;
  2409.   end
  2410.   else Result := true; { Signal no problem }
  2411. end;
  2412.  
  2413. function TFTPComponent.CreateRemoteDirectory( TheDir : String ) : Boolean;
  2414. var TheReturnString : String;  { Internal string holder }
  2415.     TheResult       : Integer; { Internal int holder    }
  2416. begin
  2417.   TheReturnString := DoCStyleFormat( 'MKD %s' ,
  2418.     [ TheDir ] );
  2419.   { Put result in progress and status line }
  2420.   AddProgressText( TheReturnString );
  2421.   ShowProgressText( TheReturnString );
  2422.   { Send Password sequence }
  2423.   TheResult := PerformFTPCommand( 'MKD %s',
  2424.                                   [ TheDir ] );
  2425.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2426.   begin
  2427.     Result := false;
  2428.     FTPCommandInProgress := false;
  2429.     exit;
  2430.   end;
  2431.   repeat
  2432.     TheResult := GetFTPServerResponse( TheReturnString );
  2433.     { Put result in progress and status line }
  2434.     AddProgressText( TheReturnString );
  2435.     ShowProgressText( TheReturnString );
  2436.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2437.   FTPCommandInProgress := false;
  2438.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2439.   begin
  2440.     { Do clever C formatting trick }
  2441.     TheReturnString :=
  2442.      DoCStyleFormat( 'Create Directory %s Failed!' ,
  2443.       [ TheDir ] );
  2444.     { Put result in progress and status line }
  2445.     AddProgressText( TheReturnString );
  2446.     ShowProgressErrorText( TheReturnString );
  2447.     { Signal error }
  2448.     Result := False;
  2449.     { leave }
  2450.     exit;
  2451.   end
  2452.   else Result := true; { Signal no problem }
  2453. end;
  2454.  
  2455.  
  2456. function TFTPComponent.DeleteRemoteFile( TheFileName : String ) : Boolean;
  2457. var TheReturnString : String;  { Internal string holder }
  2458.     TheResult       : Integer; { Internal int holder    }
  2459. begin
  2460.   TheReturnString := DoCStyleFormat( 'DELE %s' ,
  2461.     [ TheFileName ] );
  2462.   { Put result in progress and status line }
  2463.   AddProgressText( TheReturnString );
  2464.   ShowProgressText( TheReturnString );
  2465.   { Send Password sequence }
  2466.   TheResult := PerformFTPCommand( 'DELE %s',
  2467.                                   [ TheFileName ] );
  2468.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2469.   begin
  2470.     Result := false;
  2471.     FTPCommandInProgress := false;
  2472.     exit;
  2473.   end;
  2474.   repeat
  2475.     TheResult := GetFTPServerResponse( TheReturnString );
  2476.     { Put result in progress and status line }
  2477.     AddProgressText( TheReturnString );
  2478.     ShowProgressText( TheReturnString );
  2479.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2480.   FTPCommandInProgress := false;
  2481.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2482.   begin
  2483.     { Do clever C formatting trick }
  2484.     TheReturnString :=
  2485.      DoCStyleFormat( 'Delete File %s Failed!' ,
  2486.       [ TheFileName ] );
  2487.     { Put result in progress and status line }
  2488.     AddProgressText( TheReturnString );
  2489.     ShowProgressErrorText( TheReturnString );
  2490.     { Signal error }
  2491.     Result := False;
  2492.     { leave }
  2493.     exit;
  2494.   end
  2495.   else Result := true; { Signal no problem }
  2496. end;
  2497.  
  2498. { This is the FTP components PASSWORD routine }
  2499. function TFTPComponent.SendPassword(
  2500.           PCRPointer : PConnectionsRecord ) : Boolean;
  2501. var TheReturnString : String;  { Internal string holder }
  2502.     TheResult       : Integer; { Internal int holder    }
  2503. begin
  2504.   TheReturnString := 'PASS XXXXXX' + #13#10;
  2505.   { Put result in progress and status line }
  2506.   AddProgressText( TheReturnString );
  2507.   ShowProgressText( TheReturnString );
  2508.   { Send Password sequence }
  2509.   TheResult := PerformFTPCommand( 'PASS %s',
  2510.                                   [ PCRPointer^.CPassword ] );
  2511.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2512.   begin
  2513.     Result := false;
  2514.     FTPCommandInProgress := false;
  2515.     exit;
  2516.   end;
  2517.   repeat
  2518.     TheResult := GetFTPServerResponse( TheReturnString );
  2519.     { Put result in progress and status line }
  2520.     AddProgressText( TheReturnString );
  2521.     ShowProgressText( TheReturnString );
  2522.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2523.   FTPCommandInProgress := false;
  2524.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2525.   begin
  2526.     { Do clever C formatting trick }
  2527.     TheReturnString :=
  2528.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2529.       [ PCRPointer^.CIPAddress ] );
  2530.     { Put result in progress and status line }
  2531.     AddProgressText( TheReturnString );
  2532.     ShowProgressErrorText( TheReturnString );
  2533.     { Signal error }
  2534.     Result := False;
  2535.     { leave }
  2536.     exit;
  2537.   end
  2538.   else Result := true; { Signal no problem }
  2539. end;
  2540.  
  2541. { This is the FTP components CWD routine }
  2542. function TFTPComponent.SetRemoteStartupDirectory(
  2543.           PCRPointer : PConnectionsRecord ) : Boolean;
  2544. var TheReturnString : String;  { Internal string holder }
  2545.     TheResult       : Integer; { Internal int holder    }
  2546. begin
  2547.   Result := true;
  2548.   if PCRPointer^.CStartDir <> '' then
  2549.   begin
  2550.     TheReturnString :=
  2551.      DoCStyleFormat( 'CWD %s' ,
  2552.       [ PCRPointer^.CStartDir ] );
  2553.     { Put result in progress and status line }
  2554.     AddProgressText( TheReturnString );
  2555.     ShowProgressText( TheReturnString );
  2556.     { Send Password sequence }
  2557.     TheResult := PerformFTPCommand( 'CWD %s',
  2558.                                     [ PCRPointer^.CStartDir ] );
  2559.     if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2560.     begin
  2561.       Result := false;
  2562.       FTPCommandInProgress := false;
  2563.       exit;
  2564.     end;
  2565.     repeat
  2566.       TheResult := GetFTPServerResponse( TheReturnString );
  2567.       { Put result in progress and status line }
  2568.       AddProgressText( TheReturnString );
  2569.       ShowProgressText( TheReturnString );
  2570.    until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2571.    FTPCommandInProgress := false;
  2572.    if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2573.     begin
  2574.       { Do clever C formatting trick }
  2575.       TheReturnString :=
  2576.        DoCStyleFormat( 'CWD to %s Failed!' ,
  2577.         [ PCRPointer^.CStartDir ] );
  2578.       { Put result in progress and status line }
  2579.       AddProgressText( TheReturnString );
  2580.       ShowProgressErrorText( TheReturnString );
  2581.       { Signal error }
  2582.       Result := False;
  2583.       { leave }
  2584.       exit;
  2585.     end
  2586.     else Result := true; { Signal no problem }
  2587.   end;
  2588. end;
  2589.  
  2590. { This is the FTP components CWD routine }
  2591. function TFTPComponent.SetRemoteDirectory( TheDir : String ) : Boolean;
  2592. var TheReturnString : String;  { Internal string holder }
  2593.     TheResult       : Integer; { Internal int holder    }
  2594. begin
  2595.   Result := true;
  2596.   if TheDir <> '' then
  2597.   begin
  2598.     TheReturnString :=
  2599.      DoCStyleFormat( 'CWD %s' ,
  2600.       [ TheDir ] );
  2601.     { Put result in progress and status line }
  2602.     AddProgressText( TheReturnString );
  2603.     ShowProgressText( TheReturnString );
  2604.     { Send Password sequence }
  2605.     TheResult := PerformFTPCommand( 'CWD %s',
  2606.                                     [ TheDir ] );
  2607.     if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2608.     begin
  2609.       Result := false;
  2610.       FTPCommandInProgress := false;
  2611.       exit;
  2612.     end;
  2613.     repeat
  2614.       TheResult := GetFTPServerResponse( TheReturnString );
  2615.       { Put result in progress and status line }
  2616.       AddProgressText( TheReturnString );
  2617.       ShowProgressText( TheReturnString );
  2618.    until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2619.    FTPCommandInProgress := false;
  2620.    if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2621.     begin
  2622.       { Do clever C formatting trick }
  2623.       TheReturnString :=
  2624.        DoCStyleFormat( 'CWD to %s Failed!' ,
  2625.         [ TheDir ] );
  2626.       { Put result in progress and status line }
  2627.       AddProgressText( TheReturnString );
  2628.       ShowProgressErrorText( TheReturnString );
  2629.       { Signal error }
  2630.       Result := False;
  2631.       { leave }
  2632.       exit;
  2633.     end
  2634.     else Result := true; { Signal no problem }
  2635.   end;
  2636. end;
  2637.  
  2638. { This is the FTP components QUIT routine }
  2639. function TFTPComponent.Disconnect : Boolean;
  2640. var TheReturnString : String;  { Internal string holder }
  2641.     TheResult       : Integer; { Internal int holder    }
  2642. begin
  2643.   TheReturnString :=
  2644.    DoCStyleFormat( 'QUIT' ,
  2645.     [ nil ] );
  2646.   { Put result in progress and status line }
  2647.   AddProgressText( TheReturnString );
  2648.   ShowProgressText( TheReturnString );
  2649.   { Begin login sequence with user name }
  2650.   PerformFTPCommand( 'QUIT', [ nil ] );
  2651.   repeat
  2652.     TheResult := GetFTPServerResponse( TheReturnString );
  2653.     { Put result in progress and status line }
  2654.     AddProgressText( TheReturnString );
  2655.     ShowProgressText( TheReturnString );
  2656.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2657.   FTPCommandInProgress := false;
  2658.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2659.   begin
  2660.     { Do clever C formatting trick }
  2661.     TheReturnString :=
  2662.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2663.       [ nil ] );
  2664.     { Put result in progress and status line }
  2665.     AddProgressText( TheReturnString );
  2666.     ShowProgressErrorText( TheReturnString );
  2667.     { Signal error }
  2668.     Result := False;
  2669.     { leave }
  2670.     exit;
  2671.   end
  2672.   else Result := true; { Signal no problem }
  2673. end;
  2674.  
  2675. { This is the FTP components PWD routine }
  2676. function TFTPComponent.GetRemoteWorkingDirectory( var RemoteDir : String )
  2677.           : Boolean;
  2678. var TheReturnString : String;  { Internal string holder }
  2679.     TheResult       : Integer; { Internal int holder    }
  2680. begin
  2681.   TheReturnString :=
  2682.    DoCStyleFormat( 'PWD' ,
  2683.     [ nil ] );
  2684.   { Put result in progress and status line }
  2685.   AddProgressText( TheReturnString );
  2686.   ShowProgressText( TheReturnString );
  2687.   { Send Password sequence }
  2688.   TheResult := PerformFTPCommand( 'PWD',
  2689.                                   [ nil ] );
  2690.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2691.   begin
  2692.     Result := false;
  2693.     FTPCommandInProgress := false;
  2694.     exit;
  2695.   end;
  2696.   repeat
  2697.     TheResult := GetFTPServerResponse( TheReturnString );
  2698.     { Put result in progress and status line }
  2699.     AddProgressText( TheReturnString );
  2700.     ShowProgressText( TheReturnString );
  2701.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2702.   FTPCommandInProgress := false;
  2703.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2704.   begin
  2705.     { Do clever C formatting trick }
  2706.     TheReturnString :=
  2707.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2708.       [ nil ] );
  2709.     { Put result in progress and status line }
  2710.     AddProgressText( TheReturnString );
  2711.     ShowProgressErrorText( TheReturnString );
  2712.     { Signal error }
  2713.     Result := False;
  2714.     { leave }
  2715.     exit;
  2716.   end
  2717.   else
  2718.   begin
  2719.     Result := true; { Signal no problem }
  2720.     RemoteDir := TheReturnString; { Send back last string on faith }
  2721.   end;
  2722. end;
  2723.  
  2724. { This function sets up a listening port on socekt 2 and handle text replies }
  2725. function TFTPComponent.GetListeningPort : Integer;
  2726. var
  2727.   Address1 ,
  2728.   Address2 ,
  2729.   Address3 ,
  2730.   Address4        : integer; { Address integer conversions }
  2731.   IPAddress       : string;  { IP Address holder           }
  2732.   PortCommand     : string;  { Command holder              }
  2733.   TheResult       : Integer; { Result holder               }
  2734.   TheReturnString : String;  { ditto                       }
  2735. begin
  2736.   { Set up any port on socket 2 }
  2737.   Socket2.PortName := '0';
  2738.   { Listen on a socket }
  2739.   Socket2.CCSockListen;
  2740.   { Get the IP Address of socket 1 and convert it to numbers }
  2741.   IPAddress := Socket1.GetSocketIPAddress( Socket1.TheSocket );
  2742.   Address1 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress ) -1 ));
  2743.   IPAddress := copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 );
  2744.   Address2 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress) -1 ));
  2745.   IPAddress := copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 );
  2746.   Address3 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress ) -1 ));
  2747.   Address4 := StrToInt( copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 ));
  2748.   { Turn it into a command and add socket 2 stuff }
  2749.   PortCommand := format( 'PORT %d,%d,%d,%d,%d,%d' ,
  2750.    [ Address1 , Address2 , Address3 , Address4 ,
  2751.     StrToInt( Socket2.GetSocketPort( Socket2.TheMasterSocket )) Shr 8,
  2752.     StrToInt( Socket2.GetSocketPort( Socket2.TheMasterSocket )) and $ff ]);
  2753.   { Put result in progress and status line }
  2754.   AddProgressText( PortCommand + #13#10 );
  2755.   ShowProgressText( PortCommand  + #13#10 );
  2756.   TheResult := PerformFTPCommand( PortCommand , [nil] );
  2757.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2758.   begin
  2759.     Result := TCPIP_STATUS_FATAL_ERROR;
  2760.     FTPCommandInProgress := false;
  2761.     exit;
  2762.   end;
  2763.   repeat
  2764.     TheResult := GetFTPServerResponse( TheReturnString );
  2765.     { Put result in progress and status line }
  2766.     AddProgressText( TheReturnString );
  2767.     ShowProgressText( TheReturnString );
  2768.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2769.   FTPCommandInProgress := false;
  2770.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2771.   begin
  2772.     { Do clever C formatting trick }
  2773.     TheReturnString :=
  2774.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2775.       [ nil ] );
  2776.     { Put result in progress and status line }
  2777.     AddProgressText( TheReturnString );
  2778.     ShowProgressErrorText( TheReturnString );
  2779.     { Signal error }
  2780.     Result := TheResult;
  2781.     { leave }
  2782.     exit;
  2783.   end
  2784.   else
  2785.   begin
  2786.     { Return good result and leave }
  2787.     Result := TheResult;
  2788.     exit;
  2789.   end;
  2790. end;
  2791.  
  2792. { This function returns part of a unit text string }
  2793. function TFTPComponent.GetUNIXTextString( var StringIn : String ) : String;
  2794. var
  2795.   ReturnString : String;
  2796.   TheLength ,
  2797.   Counter_1   : integer;
  2798. begin
  2799.   TheLength := Length( StringIn );
  2800.   if TheLength > 1 then
  2801.   begin
  2802.     for Counter_1 := 1 to TheLength do
  2803.     begin
  2804.       if StringIn[ Counter_1 ] = #10 then
  2805.       begin
  2806.         ReturnString := HolderLine;
  2807.         HolderLine := '';
  2808.         StringIn := Copy( StringIn , Counter_1 + 1 , 255 );
  2809.         Result := ReturnString;
  2810.         exit;
  2811.       end
  2812.       else
  2813.       begin
  2814.         if StringIn[ Counter_1 ] <> #0 then
  2815.         begin
  2816.           if StringIn[ Counter_1 ] <> #13 then
  2817.            HolderLine := HolderLine + StringIn[ Counter_1 ];
  2818.         end
  2819.         else
  2820.         begin
  2821.           Result := '';
  2822.           StringIn := '';
  2823.         end;
  2824.       end;
  2825.     end;
  2826.   end;
  2827.   Result := '';
  2828.   StringIn := '';
  2829. end;
  2830.  
  2831. procedure TFTPComponent.GetFileNameFromUNIXFileName( var TheName : String );
  2832. var Counter_1 : Integer;
  2833.     ResultString : String;
  2834.     Finished : Boolean;
  2835. begin
  2836.   if Pos( 'TOTAL' , Uppercase( TheName )) <> 0 then
  2837.   begin
  2838.     TheName := '';
  2839.     exit;
  2840.   end;
  2841.   Counter_1 := Length( TheName );
  2842.   ResultString := '';
  2843.   Finished := false;
  2844.   while not Finished do
  2845.   begin
  2846.     if TheName[ Counter_1 ] <> ' ' then
  2847.     begin
  2848.       Counter_1 := Counter_1 - 1;
  2849.       if Counter_1 = 0 then
  2850.       begin
  2851.         ResultString := TheName;
  2852.         Finished := true;
  2853.       end;
  2854.     end
  2855.     else
  2856.     begin
  2857.       Finished := true;
  2858.       ResultString := Copy( TheName , Counter_1 + 1 , 255 );
  2859.     end;
  2860.   end;
  2861.   TheName := ResultString;
  2862. end;
  2863.  
  2864. { This is the FTP components get remote directory listing into a list box }
  2865. function TFTPComponent.GetRemoteDirectoryListing( TheListBox : TListBox )
  2866.           : Boolean;
  2867. var TheReturnString : String;  { Internal string holder }
  2868.     TheResult       : Integer; { Internal int holder    }
  2869.     InputString     : String;
  2870.     Through ,
  2871.     Finished        : Boolean;
  2872. begin
  2873.   TheListBox.Clear;
  2874.   TheListbox.Tag := 2;
  2875.   TheListBox.Items.Add('..');
  2876.   Result := true;
  2877.   TheReturnString :=
  2878.    DoCStyleFormat( 'TYPE A' ,
  2879.     [ nil ] );
  2880.   { Put result in progress and status line }
  2881.   AddProgressText( TheReturnString );
  2882.   ShowProgressText( TheReturnString );
  2883.   { Send Password sequence }
  2884.   TheResult := PerformFTPCommand( 'TYPE A',
  2885.                                   [ nil ] );
  2886.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2887.   begin
  2888.     Result := true;
  2889.     FTPCommandInProgress := false;
  2890.     exit;
  2891.   end;
  2892.   repeat
  2893.     TheResult := GetFTPServerResponse( TheReturnString );
  2894.     { Put result in progress and status line }
  2895.     AddProgressText( TheReturnString );
  2896.     ShowProgressText( TheReturnString );
  2897.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2898.   FTPCommandInProgress := false;
  2899.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2900.   begin
  2901.     { Do clever C formatting trick }
  2902.     TheReturnString :=
  2903.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2904.       [ nil ] );
  2905.     { Put result in progress and status line }
  2906.     AddProgressText( TheReturnString );
  2907.     ShowProgressErrorText( TheReturnString );
  2908.     { Signal error }
  2909.     Result := true;
  2910.     { leave }
  2911.     exit;
  2912.   end
  2913.   else
  2914.   begin
  2915.     { Set up socket 2 for listening }
  2916.     Socket2.AsynchMode := False;
  2917.     Socket2.NonAsynchTimeoutValue := 60;
  2918.     { do a listen and send command to server that this is receipt socket }
  2919.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  2920.     begin
  2921.       Socket2.CCSockCancelListen;
  2922.       exit;
  2923.     end;
  2924.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  2925.     TheResult := PerformFTPCommand( 'LIST' , [nil] );
  2926.     GetFTPServerResponse( TheReturnString );
  2927.     AddProgressText( TheReturnString );
  2928.     ShowProgressText( TheReturnString );
  2929.     Socket1.NonAsynchTimeoutValue := 30;
  2930.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  2931.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  2932.     begin
  2933.       TheReturnString :=
  2934.        DoCStyleFormat( 'Could not obtain remote directory!' ,
  2935.         [ nil ] );
  2936.       { Put result in progress and status line }
  2937.       AddProgressText( TheReturnString );
  2938.       ShowProgressErrorText( TheReturnString );
  2939.       Socket2.CCSockCancelListen;
  2940.       Result := true;
  2941.       exit;
  2942.     end;
  2943.     Socket2.CCSockAccept;
  2944.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  2945.     begin
  2946.       TheReturnString :=
  2947.        DoCStyleFormat( 'Could not establish receive socket!' ,
  2948.         [ nil ] );
  2949.       { Put result in progress and status line }
  2950.       AddProgressText( TheReturnString );
  2951.       ShowProgressErrorText( TheReturnString );
  2952.       Result := true;
  2953.       exit;
  2954.     end;
  2955.     Through := false;
  2956.     repeat
  2957.       TheReturnString := Socket2.StringData;
  2958.       if Length( TheReturnString ) = 0 then Through := true;
  2959.       if Length( TheReturnString ) > 0 then
  2960.       begin
  2961.         finished := false;
  2962.         while not finished do
  2963.         begin
  2964.           InputString := GetUNIXTextString( TheReturnString );
  2965.           if InputString = '' then Finished := true else
  2966.           begin
  2967.             GetFileNameFromUNIXFileName( InputString);
  2968.             If InputString <> '' then
  2969.             TheListBox.Items.Add( InputString );
  2970.           end;
  2971.         end;
  2972.       end;
  2973.       if GlobalAbortedFlag then
  2974.       begin
  2975.         Socket1.OutOfBand := 'ABOR'+#13#10;
  2976.         repeat
  2977.           TheResult := GetFTPServerResponse( TheReturnString );
  2978.           { Put result in progress and status line }
  2979.           AddProgressText( TheReturnString );
  2980.           ShowProgressText( TheReturnString );
  2981.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2982.         result := true;
  2983.         exit;
  2984.       end;
  2985.     until Through;
  2986.     GetFTPServerResponse( TheReturnString );
  2987.     AddProgressText( TheReturnString );
  2988.     ShowProgressText( TheReturnString );
  2989.     { cancel listening on second socket and close it }
  2990.     Socket2.CCSockCancelListen;
  2991.     Socket2.CCSockClose;
  2992.   end;
  2993.   FTPCommandInProgress := false;
  2994. end;
  2995.  
  2996. { This is the FTP components get remote directory listing into a list box }
  2997. function TFTPComponent.GetRemoteDirectoryListingToMemo : Boolean;
  2998. var TheReturnString : String;  { Internal string holder }
  2999.     TheResult       : Integer; { Internal int holder    }
  3000.     Through         : Boolean;
  3001. begin
  3002.   Result := true;
  3003.   TheReturnString :=
  3004.    DoCStyleFormat( 'TYPE A' ,
  3005.     [ nil ] );
  3006.   { Put result in progress and status line }
  3007.   AddProgressText( TheReturnString );
  3008.   ShowProgressText( TheReturnString );
  3009.   { Send Password sequence }
  3010.   TheResult := PerformFTPCommand( 'TYPE A',
  3011.                                   [ nil ] );
  3012.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  3013.   begin
  3014.     Result := true;
  3015.     FTPCommandInProgress := false;
  3016.     exit;
  3017.   end;
  3018.   repeat
  3019.     TheResult := GetFTPServerResponse( TheReturnString );
  3020.     { Put result in progress and status line }
  3021.     AddProgressText( TheReturnString );
  3022.     ShowProgressText( TheReturnString );
  3023.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  3024.   FTPCommandInProgress := false;
  3025.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  3026.   begin
  3027.     { Do clever C formatting trick }
  3028.     TheReturnString :=
  3029.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  3030.       [ nil ] );
  3031.     { Put result in progress and status line }
  3032.     AddProgressText( TheReturnString );
  3033.     ShowProgressErrorText( TheReturnString );
  3034.     { Signal error }
  3035.     Result := true;
  3036.     { leave }
  3037.     exit;
  3038.   end
  3039.   else
  3040.   begin
  3041.     { Set up socket 2 for listening }
  3042.     Socket2.AsynchMode := False;
  3043.     Socket2.NonAsynchTimeoutValue := 30;
  3044.     { do a listen and send command to server that this is receipt socket }
  3045.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  3046.     begin
  3047.       Socket2.CCSockCancelListen;
  3048.       exit;
  3049.     end;
  3050.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  3051.     TheResult := PerformFTPCommand( 'LIST' , [nil] );
  3052.     GetFTPServerResponse( TheReturnString );
  3053.     AddProgressText( TheReturnString );
  3054.     ShowProgressText( TheReturnString );
  3055.     Socket1.NonAsynchTimeoutValue := 30;
  3056.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  3057.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  3058.     begin
  3059.       TheReturnString :=
  3060.        DoCStyleFormat( 'Could not obtain remote directory!' ,
  3061.         [ nil ] );
  3062.       { Put result in progress and status line }
  3063.       AddProgressText( TheReturnString );
  3064.       ShowProgressErrorText( TheReturnString );
  3065.       Socket2.CCSockCancelListen;
  3066.       Result := true;
  3067.       exit;
  3068.     end;
  3069.     Socket2.CCSockAccept;
  3070.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  3071.     begin
  3072.       TheReturnString :=
  3073.        DoCStyleFormat( 'Could not establish receive socket!' ,
  3074.         [ nil ] );
  3075.       { Put result in progress and status line }
  3076.       AddProgressText( TheReturnString );
  3077.       ShowProgressErrorText( TheReturnString );
  3078.       Result := true;
  3079.       exit;
  3080.     end;
  3081.     Through := false;
  3082.     repeat
  3083.       TheReturnString := Socket2.StringData;
  3084.       if Length( TheReturnString ) = 0 then Through := true;
  3085.       if Length( TheReturnString ) > 0 then
  3086.       begin
  3087.         { Put result in progress and status line }
  3088.         AddProgressText( TheReturnString );
  3089.         ShowProgressText( TheReturnString );
  3090.       end;
  3091.       if GlobalAbortedFlag then
  3092.       begin
  3093.         Socket1.OutOfBand := 'ABOR'+#13#10;
  3094.         repeat
  3095.           TheResult := GetFTPServerResponse( TheReturnString );
  3096.           { Put result in progress and status line }
  3097.           AddProgressText( TheReturnString );
  3098.           ShowProgressText( TheReturnString );
  3099.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  3100.         result := true;
  3101.         exit;
  3102.       end;
  3103.     until Through;
  3104.     GetFTPServerResponse( TheReturnString );
  3105.     AddProgressText( TheReturnString );
  3106.     ShowProgressText( TheReturnString );
  3107.     { cancel listening on second socket and close it }
  3108.     Socket2.CCSockCancelListen;
  3109.     Socket2.CCSockClose;
  3110.   end;
  3111. end;
  3112.  
  3113. { This is the FTP components get local directory listing into a list box }
  3114. function TFTPComponent.GetLocalDirectoryAndListing( var TheString : String;
  3115.                                                         TheListBox : TListBox )
  3116.           : Boolean;
  3117. var TheFLB : TFileListBox;
  3118. begin
  3119.   { Get the working directory }
  3120.   GetDir( 0 , TheString );
  3121.   { Clear incoming LB }
  3122.   TheListBox.Clear;
  3123.   TheListBox.Tag := 2;
  3124.   TheFLB := TFileListBox.Create( Application.MainForm );
  3125.   TheFLB.Visible := false;
  3126.   TheFLB.Parent := Application.MainForm;
  3127.   TheFLB.FileType := [ ftNormal , ftDirectory ];
  3128.   TheFLB.Directory := TheString;
  3129.   TheFLB.Update;
  3130.   TheListBox.Items.Assign( TheFLB.Items );
  3131.   TheFLB.Free;
  3132.   result := true;
  3133. end;
  3134.  
  3135. { This is a clever c-style formatting trick }
  3136. function TFTPComponent.DoCStyleFormat(
  3137.                 TheText      : string;
  3138.           const TheArguments : array of const ) : String;
  3139. begin
  3140.   Result := Format( TheText , TheArguments ) + #13#10;
  3141. end;
  3142.  
  3143. function TFTPComponent.GetQuotedString( TheString : String ) : String;
  3144. var TheIndex     : Integer; { Holder var }
  3145.     ResultString : String;  { ditto      }
  3146. begin
  3147.   { Find out if " present at all }
  3148.   TheIndex := Pos( '"' , TheString );
  3149.   If TheIndex = 0 then
  3150.   begin
  3151.     { If not, return null string and exit }
  3152.     Result := '';
  3153.     exit;
  3154.   end
  3155.   else
  3156.   begin
  3157.     { Get from first " to end of string in holder }
  3158.     ResultString := Copy( TheString , TheIndex + 1 , 255 );
  3159.     { Find position to second " }
  3160.     TheIndex := Pos( '"' , ResultString );
  3161.     { If no ending " then return whole string and leave }
  3162.     if TheIndex = 0 then
  3163.     begin
  3164.       Result := ResultString;
  3165.       exit;
  3166.     end
  3167.     else
  3168.     begin
  3169.       { Get internal text between quotes and exit }
  3170.       ResultString := Copy( ResultString , 1 , TheIndex - 1 );
  3171.       Result := ResultString;
  3172.     end;
  3173.   end;
  3174. end;
  3175.  
  3176. procedure TCCINetCCForm.UpdateGauge( BytesFinished , TotalToHandle : longint );
  3177. var
  3178.   Percentage : longint;
  3179. begin
  3180.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3181.   if TotalToHandle = 0 then exit;
  3182.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3183.   Gauge1.Progress := Percentage;
  3184.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3185.    ' bytes ' + FileNameToXFer + ' (' + IntToStr( Percentage ) + '% Done)';
  3186. end;
  3187.  
  3188. procedure TCCINetCCForm.UpdateMailGauge( BytesFinished , TotalToHandle : longint );
  3189. var
  3190.   Percentage : longint;
  3191. begin
  3192.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3193.   if TotalToHandle = 0 then exit;
  3194.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3195.   Gauge1.Progress := Percentage;
  3196.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3197.    ' bytes mail (' + IntToStr( Percentage ) + '% Done)';
  3198. end;
  3199.  
  3200. procedure TCCINetCCForm.UpdateMIMEGauge( BytesFinished , TotalToHandle : longint );
  3201. var
  3202.   Percentage : longint;
  3203. begin
  3204.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3205.   if TotalToHandle = 0 then exit;
  3206.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3207.   Gauge1.Progress := Percentage;
  3208.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3209.    ' bytes MIME (' + IntToStr( Percentage ) + '% Done)';
  3210. end;
  3211.  
  3212. procedure TCCINetCCForm.UpdateUUGauge( BytesFinished , TotalToHandle : longint );
  3213. var
  3214.   Percentage : longint;
  3215. begin
  3216.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3217.   if TotalToHandle = 0 then exit;
  3218.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3219.   Gauge1.Progress := Percentage;
  3220.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3221.    ' bytes UUCode (' + IntToStr( Percentage ) + '% Done)';
  3222.   Panel1.Show;
  3223. end;
  3224.  
  3225. { This procedure actually attempts to connect to the internet at an ftp site }
  3226. function TCCINetCCForm.DoFTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  3227. var TheReturnString : String; { Display results of connection in status lines }
  3228. begin
  3229.   { Create the component }
  3230.   Result := false;
  3231.   { Do busy cursors }
  3232.   SetHGCursors;
  3233.   if not TheFTPComponent.EstablishConnection( PCRPointer ) then
  3234.   begin
  3235.     { Do saved cursors }
  3236.     TheFTPComponent.FTPCommandInProgress := false;
  3237.     TheFTPComponent.Connection_Established := false;
  3238.     SetNormalCursors;
  3239.     exit;
  3240.   end
  3241.   else
  3242.   begin { Connected; continue login process }
  3243.     if not TheFTPComponent.LoginUser( PCRPointer ) then
  3244.     begin
  3245.       { Do saved cursors }
  3246.       TheFTPComponent.FTPCommandInProgress := false;
  3247.       TheFTPComponent.Connection_Established := false;
  3248.       SetNormalCursors;
  3249.       exit;
  3250.     end;
  3251.     if not TheFTPComponent.SendPassword( PCRPointer ) then
  3252.     begin
  3253.       { Do saved cursors }
  3254.       TheFTPComponent.FTPCommandInProgress := false;
  3255.       TheFTPComponent.Connection_Established := false;
  3256.       SetNormalCursors;
  3257.       exit;
  3258.     end;
  3259.     if not TheFTPComponent.SetRemoteStartupDirectory( PCRPointer ) then
  3260.     begin
  3261.       { Do saved cursors }
  3262.       SetNormalCursors;
  3263.       TheFTPComponent.Connection_Established := false;
  3264.       TheFTPComponent.FTPCommandInProgress := false;
  3265.       exit;
  3266.     end;
  3267.     if not TheFTPComponent.GetRemoteWorkingDirectory( TheReturnString ) then
  3268.     begin
  3269.       { Do saved cursors }
  3270.       TheFTPComponent.Connection_Established := false;
  3271.       TheFTPComponent.FTPCommandInProgress := false;
  3272.       SetNormalCursors;
  3273.       exit;
  3274.     end;
  3275.     { Put up remote directory via PWD and strip quotes }
  3276.     Label4.Caption := TheFTPComponent.GetQuotedString( TheReturnString );
  3277.     { Get the listings of directories and exit OK }
  3278.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  3279.     TheFTPComponent.GetLocalDirectoryAndListing( TheReturnString ,
  3280.      Listbox2 );
  3281.     if Label5.Canvas.TextWidth( TheReturnString ) > Label5.Width then
  3282.      TheReturnString := TheFTPComponent.GetShortPathName( TheReturnString );
  3283.     Label5.Caption := TheReturnString;
  3284.     SetNormalCursors;
  3285.     Result := true;
  3286.     EnableFTPMenus;
  3287.     TheFTPComponent.FTPCommandInProgress := false;
  3288.     Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  3289.   end;
  3290. end;
  3291.  
  3292. { This procedure actually attempts to connect to the internet at an nntp site }
  3293. function TCCINetCCForm.DoNNTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  3294. begin
  3295.   { Create the component }
  3296.   Result := false;
  3297.   { Do busy cursors }
  3298.   SetHGCursors;
  3299.   if not TheNNTPComponent.EstablishConnection( PCRPointer ) then
  3300.   begin
  3301.     { Do saved cursors }
  3302.     TheNNTPComponent.NNTPCommandInProgress := false;
  3303.     TheNNTPComponent.Connection_Established := false;
  3304.     SetNormalCursors;
  3305.     exit;
  3306.   end
  3307.   else
  3308.   begin { Connected; continue login process }
  3309.     SetNormalCursors;
  3310.     Result := true;
  3311.     EnableNNTPMenus;
  3312.     TheNNTPComponent.NNTPCommandInProgress := false;
  3313.     Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  3314.   end;
  3315. end;
  3316.  
  3317. { This procedure actually attempts to disconnect to the internet at an ftp site}
  3318. procedure TCCINetCCForm.DoFTPDisconnect;
  3319. begin
  3320.   { Call QUIT command }
  3321.   TheFTPComponent.Disconnect;
  3322.   { Kill the socket }
  3323.   TheFTPComponent.Socket1.CCSockClose;
  3324. end;
  3325.  
  3326. { This procedure actually attempts to disconnect to the internet at an ftp site}
  3327. procedure TCCINetCCForm.DoNNTPDisconnect;
  3328. begin
  3329.   { Call QUIT command }
  3330.   TheNNTPComponent.Disconnect;
  3331.   { Kill the socket }
  3332.   TheNNTPComponent.Socket1.CCSockClose;
  3333. end;
  3334.  
  3335. { This procedure reads in the ini file and default path info }
  3336. procedure TCCINetCCForm.ReadIniData;
  3337. begin
  3338.   TheICCIniFile := TIniFile.Create( 'CCICC.INI' );
  3339.   MailPath := TheICCIniFile.ReadString( 'Paths','MailPath','C:\WINDOWS' );
  3340.   NewsPath := TheICCIniFile.ReadString( 'Paths','NewsPath','C:\WINDOWS' );
  3341.   FTPPath := TheICCIniFile.ReadString( 'Paths','FTPPath','C:\WINDOWS' );
  3342.   PasswordControlVector := TheICCIniFile.ReadInteger( 'Vectors','PWControl',2 );
  3343.   DefaultDownloadVector := TheICCIniFile.ReadInteger( 'Vectors','DefDL', 3 );
  3344.   TheAnonRedialVector := TheICCIniFile.ReadInteger( 'Vectors','AnonRD', 20 );
  3345.   NewsReadArticlePurgingVector := TheICCIniFile.ReadInteger( 'Vectors','NewsPurge', 1 );
  3346.   NewsPostQueueingVector := TheICCIniFile.ReadInteger( 'Vectors','NewsQueue', 1 );
  3347.   NewsReadArticleDisplayVector := TheICCIniFile.ReadInteger( 'Vectors','NewsRDisp', 1 );
  3348.   NewsUUMIMEVector := TheICCIniFile.ReadInteger( 'Vectors','NewsUUMIME', 2 );
  3349.   NewsInitialUpdateVector := TheICCIniFile.ReadInteger( 'Vectors','NewsInitUD', 1 );
  3350.   EMPasswordControlVector := TheICCIniFile.ReadInteger( 'Vectors','EMPWControl', 1 );
  3351.   EMRemoteDeletionVector  := TheICCIniFile.ReadInteger( 'Vectors','EMRemDel', 2 );
  3352.   EMChokeVector           := TheICCIniFile.ReadInteger( 'Vectors','EMChoke', 1 );
  3353.   EMDefaultDownloadVector := TheICCIniFile.ReadInteger( 'Vectors','EMInitUD', 1 );
  3354.   EMQueueVector           := TheICCIniFile.ReadInteger( 'Vectors','EMQueue', 1 );
  3355.   TheICCIniFile.Free;
  3356. end;
  3357.  
  3358. { This procedure writes out default path data to the ini file }
  3359. procedure TCCINetCCForm.WriteIniData;
  3360. begin
  3361.   TheICCIniFile := TIniFile.Create( 'CCICC.INI' );
  3362.   TheICCIniFile.WriteString( 'Paths','MailPath', MailPath );
  3363.   TheICCIniFile.WriteString( 'Paths','NewsPath', NewsPath );
  3364.   TheICCIniFile.WriteString( 'Paths','FTPPath', FTPPath );
  3365.   TheICCIniFile.WriteInteger( 'Vectors','PWControl', PasswordControlVector );
  3366.   TheICCIniFile.WriteInteger( 'Vectors','DefDL', DefaultDownloadVector );
  3367.   TheICCIniFile.WriteInteger( 'Vectors','AnonRD', TheAnonRedialVector );
  3368.   TheICCIniFile.WriteInteger( 'Vectors','NewsPurge',
  3369.    NewsReadArticlePurgingVector );
  3370.   TheICCIniFile.WriteInteger( 'Vectors','NewsQueue', NewsPostQueueingVector );
  3371.   TheICCIniFile.WriteInteger( 'Vectors','NewsRDisp',
  3372.    NewsReadArticleDisplayVector );
  3373.   TheICCIniFile.WriteInteger( 'Vectors','NewsUUMIME', NewsUUMIMEVector );
  3374.   TheICCIniFile.WriteInteger( 'Vectors','NewsInitUD', NewsInitialUpdateVector );
  3375.   TheICCIniFile.WriteInteger( 'Vectors','EMPWControl', EMPasswordControlVector );
  3376.   TheICCIniFile.WriteInteger( 'Vectors','EMRemDel', EMRemoteDeletionVector );
  3377.   TheICCIniFile.WriteInteger( 'Vectors','EMChoke', EMChokeVector );
  3378.   TheICCIniFile.WriteInteger( 'Vectors','EMInitUD', EMDefaultDownloadVector );
  3379.   TheICCIniFile.WriteInteger( 'Vectors','EMQueue', EMQueueVector );
  3380.   TheICCIniFile.Free;
  3381. end;
  3382.  
  3383. { Procedure to load the FTP Site list }
  3384. procedure TCCINetCCForm.LoadFTPSiteFile;
  3385. var TheTCRecord : PConnectionsRecord; { Generic TCR Pointer    }
  3386.     FTPSLName   : String;             { FTP Site List filename }
  3387.     Counter_1   : Integer;            { Loop counter           }
  3388. begin
  3389.   { Create the sites list list }
  3390.   TheFTPSiteList := TList.Create;
  3391.   { Set up the FTP sites list file name }
  3392.   FTPSLName := FTPPath + '\FTPSITES.TCR';
  3393.   { If the FTP Site List exists load it in }
  3394.   if FileExists( FTPSLName ) then
  3395.   begin
  3396.     { set up the file and open it }
  3397.     AssignFile( TheFTPSiteFile , FTPSLName );
  3398.     Reset( TheFTPSiteFile );
  3399.     { read in the records }
  3400.     for Counter_1 := 0 to FileSize( TheFTPSiteFile ) - 1 do
  3401.     begin
  3402.       { Create the TCRecord }
  3403.       New( TheTCRecord );
  3404.       { Read in the data record }
  3405.       Seek( TheFTPSiteFile , Counter_1 );
  3406.       Read( TheFTPSiteFile , TheTCRecord^ );
  3407.       { Add the record to the list }
  3408.       TheFTPSiteList.Add( TheTCRecord );
  3409.     end;
  3410.     { close the file }
  3411.     CloseFile( TheFTPSiteFile );
  3412.   end
  3413.   else
  3414.   { Otherwise create a default one with a few anonymous sites }
  3415.   begin
  3416.     { create new record }
  3417.     New( TheTCRecord );
  3418.     { fill in its info }
  3419.     with TheTCRecord^ do
  3420.     begin
  3421.       CProfile   := 'Winsite Windows Archive';
  3422.       CIPAddress := 'ftp.winsite.com';
  3423.       CUserName  := 'anonymous';
  3424.       CPassword  := 'guest@nowhere.com';
  3425.       CStartDir  := '/pub';
  3426.     end;
  3427.     { add it to the list }
  3428.     { do it three more times }
  3429.     TheFTPSiteList.Add( TheTCRecord );
  3430.     New( TheTCRecord );
  3431.     with TheTCRecord^ do
  3432.     begin
  3433.       CProfile   := 'Digital Equipment Corp';
  3434.       CIPAddress := 'gatekeeper.dec.com';
  3435.       CUserName  := 'anonymous';
  3436.       CPassword  := 'guest@nowhere.com';
  3437.       CStartDir  := '/pub';
  3438.     end;
  3439.     TheFTPSiteList.Add( TheTCRecord );
  3440.     New( TheTCRecord );
  3441.     with TheTCRecord^ do
  3442.     begin
  3443.       CProfile   := 'Microsoft FTP Site';
  3444.       CIPAddress := 'ftp.microsoft.com';
  3445.       CUserName  := 'anonymous';
  3446.       CPassword  := 'guest@nowhere.com';
  3447.       CStartDir  := '/pub';
  3448.     end;
  3449.     TheFTPSiteList.Add( TheTCRecord );
  3450.     New( TheTCRecord );
  3451.     with TheTCRecord^ do
  3452.     begin
  3453.       CProfile   := 'Oakland MSDOS Archive';
  3454.       CIPAddress := 'oak.oakland.edu';
  3455.       CUserName  := 'anonymous';
  3456.       CPassword  := 'guest@nowhere.com';
  3457.       CStartDir  := '/pub';
  3458.     end;
  3459.     TheFTPSiteList.Add( TheTCRecord );
  3460.     { create the file and write out the data, then close it }
  3461.     AssignFile( TheFTPSiteFile , FTPSLName );
  3462.     Rewrite( TheFTPSiteFile );
  3463.     for Counter_1 := 0 to 3 do
  3464.     begin
  3465.       TheTCRecord :=
  3466.        PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] );
  3467.       Seek( TheFTPSiteFile , Counter_1 );
  3468.       Write( TheFTPSiteFile , TheTCRecord^ );
  3469.     end;
  3470.     CloseFile( TheFTPSiteFile );
  3471.   end;
  3472.   { Create the working copy for use to make safe changes in info dlg }
  3473.   TheWorkingFTPSL := TList.Create;
  3474.   For Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3475.   begin
  3476.     New( TheTCRecord );
  3477.     TheTCRecord^ := PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] )^;
  3478.     TheWorkingFTPSL.Add( TheTCRecord );
  3479.   end;
  3480. end;
  3481.  
  3482. { Procedure to load the NNTP Site list }
  3483. procedure TCCINetCCForm.LoadNNTPSiteFile;
  3484. var TheNGRecord : PConnectionsRecord; { Generic TCR Pointer    }
  3485.     NNTPSLName  : String;             { NNTP Site List filename }
  3486.     Counter_1   : Integer;            { Loop counter           }
  3487. begin
  3488.   { Create the sites list list }
  3489.   TheNewsServerList := TList.Create;
  3490.   { Set up the FTP sites list file name }
  3491.   NNTPSLName := NewsPath + '\NNTPSITE.TCR';
  3492.   { If the FTP Site List exists load it in }
  3493.   if FileExists( NNTPSLName ) then
  3494.   begin
  3495.     { set up the file and open it }
  3496.     AssignFile( TheNewsServerFile , NNTPSLName );
  3497.     Reset( TheNewsServerFile );
  3498.     { read in the records }
  3499.     for Counter_1 := 0 to FileSize( TheNewsServerFile ) - 1 do
  3500.     begin
  3501.       { Create the TCRecord }
  3502.       New( TheNGRecord );
  3503.       { Read in the data record }
  3504.       Seek( TheNewsServerFile , Counter_1 );
  3505.       Read( TheNewsServerFile , TheNGRecord^ );
  3506.       { Add the record to the list }
  3507.       TheNewsServerList.Add( TheNGRecord );
  3508.     end;
  3509.     { close the file }
  3510.     CloseFile( TheNewsServerFile );
  3511.   end
  3512.   else
  3513.   { Otherwise create a default one with a generic news site (?) }
  3514.   begin
  3515.     { create new record }
  3516.     New( TheNGRecord );
  3517.     { fill in its info }
  3518.     with TheNGRecord^ do
  3519.     begin
  3520.       CProfile   := 'My News Server';
  3521.       CIPAddress := 'news.myprovider.com';
  3522.       CUserName  := '';
  3523.       CPassword  := '';
  3524.       CStartDir  := '';
  3525.     end;
  3526.     { add it to the list }
  3527.     { do it three more times }
  3528.     TheNewsServerList.Add( TheNGRecord );
  3529.     { create the file and write out the data, then close it }
  3530.     AssignFile( TheNewsServerFile , NNTPSLName );
  3531.     Rewrite( TheNewsServerFile );
  3532.     TheNGRecord :=
  3533.        PConnectionsRecord( TheNewsServerList.Items[ 0 ] );
  3534.       Seek( TheNewsServerFile , 0 );
  3535.       Write( TheNewsServerFile , TheNGRecord^ );
  3536.     CloseFile( TheNewsServerFile );
  3537.   end;
  3538.   TheWorkingNSSL := TList.Create;
  3539.   For Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3540.   begin
  3541.     New( TheNGRecord );
  3542.     TheNGRecord^ := PConnectionsRecord( TheNewsServerList.Items[ Counter_1 ] )^;
  3543.     TheWorkingNSSL.Add( TheNGRecord );
  3544.   end;
  3545. end;
  3546.  
  3547. { This procedure saves off the FTP Site List }
  3548. procedure TCCINetCCForm.SaveFTPSiteFile;
  3549. var TheTCRecord : PConnectionsRecord; { The TC Record pointer  }
  3550.     FTPSLName   : String;             { FTP Site List filename }
  3551.     Counter_1   : Integer;            { Loop counter           }
  3552. begin
  3553.   { Set up the file name }
  3554.   FTPSLName := FTPPath + '\FTPSITES.TCR';
  3555.   { Assign the file }
  3556.   AssignFile( TheFTPSiteFile , FTPSLName );
  3557.   { Rewrite it }
  3558.   Rewrite( TheFTPSiteFile );
  3559.   { run the list through the procedure }
  3560.   for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3561.   begin
  3562.     { get the record from the list }
  3563.     TheTCRecord :=
  3564.      PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] );
  3565.     { Do the seek/write }
  3566.     Seek( TheFTPSiteFile , Counter_1 );
  3567.     Write( TheFTPSiteFile , TheTCRecord^ );
  3568.     { free the record }
  3569.     Dispose( TheTCRecord );
  3570.   end;
  3571.   { Close the file }
  3572.   CloseFile( TheFTPSiteFile );
  3573.   { Free the list pointers }
  3574.   TheFTPSiteList.Free;
  3575.   TheWorkingFTPSL.Free;
  3576. end;
  3577.  
  3578. { This procedure saves off the FTP Site List }
  3579. procedure TCCINetCCForm.SaveNNTPSiteFile;
  3580. var TheNGRecord : PConnectionsRecord; { The TC Record pointer   }
  3581.     NNTPSLName   : String;            { NNTP Site List filename }
  3582.     Counter_1   : Integer;            { Loop counter           }
  3583. begin
  3584.   { Set up the file name }
  3585.   NNTPSLName := NewsPath + '\NNTPSITE.TCR';
  3586.   { Assign the file }
  3587.   AssignFile( TheNewsServerFile , NNTPSLName );
  3588.   { Rewrite it }
  3589.   Rewrite( TheNewsServerFile );
  3590.   { run the list through the procedure }
  3591.   for Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3592.   begin
  3593.     { get the record from the list }
  3594.     TheNGRecord :=
  3595.      PConnectionsRecord( TheNewsServerList.Items[ Counter_1 ] );
  3596.     { Do the seek/write }
  3597.     Seek( TheNewsServerFile , Counter_1 );
  3598.     Write( TheNewsServerFile , TheNGRecord^ );
  3599.     { free the record }
  3600.     Dispose( TheNGRecord );
  3601.   end;
  3602.   { Close the file }
  3603.   CloseFile( TheNewsServerFile );
  3604.   { Free the list pointers }
  3605.   TheNewsServerList.Free;
  3606.   TheWorkingNSSL.Free;
  3607. end;
  3608.  
  3609. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3610. procedure TCCINetCCForm.SetupFTPSiteLists;
  3611. var Counter_1  : Integer;            { Loop counter        }
  3612. begin
  3613.   { Set up display for main form }
  3614.   CCINetCCForm.Tag := 2;
  3615.   CCINetCCForm.Caption := 'CC Internet Command Center -- FTP Mode';
  3616.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  3617.   CCINetCCForm.FTP1.Enabled := false;
  3618.   CCINetCCForm.FTP2.Enabled := true;
  3619.   CCINetCCForm.Label1.Caption := 'FTP Site:';
  3620.   CCINetCCForm.Button1.Caption := 'Connect';
  3621.   CCINetCCForm.Label4.Caption := 'Local Dir';
  3622.   CCINetCCForm.Label5.Caption := 'Remote Dir';
  3623.   { Set tag for FTP stuff }
  3624.   CCICInfoDlg.Tag := 2;
  3625.   { set up caption of main label }
  3626.   CCICInfoDlg.Label2.Caption := 'FTP Sites';
  3627.   { hide outline panel }
  3628.   CCICInfoDlg.Panel6.Visible := false;
  3629.   { clear the list box }
  3630.   CCICInfoDlg.ListBox2.Clear;
  3631.   CCINetCCForm.ComboBox1.Clear;
  3632.   { add profile strings to the list box }
  3633.   for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3634.   begin
  3635.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  3636.      TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  3637.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  3638.      TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  3639.   end;
  3640.   { Set up caption of special button }
  3641.   CCICInfoDlg.Button1.Caption := 'Anonymous Login';
  3642.   { Start with top record }
  3643.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  3644.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  3645.   { put in data from top record and reset captions }
  3646.   with PConnectionsRecord( TheFTPSiteList.Items[ 0 ] )^ do
  3647.   begin
  3648.     with CCICInfoDlg do
  3649.     begin
  3650.       Edit1.Text := CProfile;
  3651.       Panel2.Caption := '            Name:';
  3652.       Edit2.Text := CIPAddress;
  3653.       Panel3.Caption := '     IP Address:';
  3654.       Edit3.Text := CUserName;
  3655.       Panel5.Caption := '    User Name:';
  3656.       case PasswordControlVector of
  3657.         1 : Edit4.Text := CPassword;
  3658.         2 : Edit4.Text := '**********';
  3659.       end;
  3660.       Panel8.Caption := '      Password:';
  3661.       Edit5.Text := CStartDir;
  3662.       Panel9.Caption := '    Starting Dir:';
  3663.     end;
  3664.   end;
  3665. end;
  3666.  
  3667. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3668. procedure TCCINetCCForm.SetupNNTPSiteLists;
  3669. begin
  3670.   { Set up display for main form }
  3671.   CCINetCCForm.Tag := 4; { Usenet News Tag }
  3672.   CCINetCCForm.Caption := 'CC Internet Command Center -- Usenet News Mode';
  3673.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  3674.   CCINetCCForm.FTP1.Enabled := true;
  3675.   CCINetCCForm.FTP2.Enabled := false;
  3676.   CCINetCCForm.UsenetNws1.Enabled := false;
  3677.   CCINetCCForm.News1.Enabled := true;
  3678.   CCINetCCForm.Label1.Caption := 'NNTP Server:';
  3679.   CCINetCCForm.Button1.Caption := 'Connect';
  3680.   CCINetCCForm.Label4.Caption := 'SubScribed Groups';
  3681.   CCINetCCForm.Label5.Caption := 'Unread Articles';
  3682.   { Create the working copy for use to make safe changes in info dlg }
  3683. end;
  3684.  
  3685. { This method saves off the Newsgroup and Article Lists }
  3686. procedure TCCINetCCForm.SaveNNTPNewsGroupLists;
  3687. var TheNGRecord : PNewsGroupRecord; { Generic NGR Pointer       }
  3688.     TheNGARecord : PNewsGroupArticleRecord; {  }
  3689.     WorkingList : TList;
  3690.     Counter_1 ,
  3691.     Counter_2   : Integer;          { Loop counter              }
  3692.     NNTPNGLName ,                   { NewsGroup Articles fname  }
  3693.     NNTPARName  : String;           { NNTP NewsRC filename      }
  3694. begin
  3695.   { Abort if no server to select }
  3696.   if ComboBox1.ItemIndex = -1 then exit;
  3697.   { Get number of server in list }
  3698.   WhichServer := ComboBox1.ItemIndex;
  3699.   { Set up the FTP sites list file name }
  3700.   NNTPNGLName := NewsPath + '\NEWSRC ' + IntToStr( WhichServer ) + '.NRC';
  3701.   { If the FTP Site List exists load it in }
  3702.   { set up the file and open it }
  3703.   AssignFile( TheNewsRCFile , NNTPNGLName );
  3704.   ReWrite( TheNewsRCFile );
  3705.   { read in the records }
  3706.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3707.   begin
  3708.     { Create the TCRecord }
  3709.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3710.     { Read in the data record }
  3711.     Seek( TheNewsRCFile , Counter_1 );
  3712.     Write( TheNewsRCFile , TheNGRecord^ );
  3713.     { Add the record to the list }
  3714.     WorkingList := TList( TheNGRecord^.GLTag );
  3715.     if WorkingList.Count > 0 then
  3716.     begin
  3717.       NNTPARName := TheNGRecord^.GFileName;
  3718.       TheNGArticlesList := TList.Create;
  3719.       AssignFile( TheNewsArticleFile , NewsPath + '\' + NNTPARName );
  3720.       ReWrite( TheNewsArticleFile );
  3721.       for Counter_2 := 0 to WorkingList.Count - 1 do
  3722.       begin
  3723.         TheNGARecord :=
  3724.          PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  3725.         Seek( TheNewsArticleFile , Counter_2 );
  3726.         Write( TheNewsArticleFile , TheNGARecord^ );
  3727.         Dispose( TheNGARecord );
  3728.       end;
  3729.       CloseFile( TheNewsArticleFile );
  3730.     end;
  3731.     WorkingList.Free;
  3732.     Dispose( TheNGRecord );
  3733.   end;
  3734.   { close the file }
  3735.   CloseFile( TheNewsRCFile );
  3736.   { Free the list itself }
  3737.   TheNewsRCList.Free;
  3738. end;
  3739.  
  3740. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3741. procedure TCCINetCCForm.SetupNNTPNewsGroupLists;
  3742. var TheNGRecord : PNewsGroupRecord; { Generic NGR Pointer       }
  3743.     TheNGARecord : PNewsGroupArticleRecord; {  }
  3744.     Counter_1 ,
  3745.     Counter_2   : Integer;          { Loop counter              }
  3746.     NNTPNGLName ,                   { NewsGroup Articles fname  }
  3747.     NNTPARName  : String;           { NNTP NewsRC filename      }
  3748. begin
  3749.   { Abort if no server to select }
  3750.   if ComboBox1.ItemIndex = -1 then exit;
  3751.   { Get number of server in list }
  3752.   WhichServer := ComboBox1.ItemIndex;
  3753.   { Create the sites list list }
  3754.   TheNewsRCList := TList.Create;
  3755.   { Set up the FTP sites list file name }
  3756.   NNTPNGLName := NewsPath + '\NEWSRC ' + IntToStr( WhichServer ) + '.NRC';
  3757.   { If the FTP Site List exists load it in }
  3758.   if FileExists( NNTPNGLName ) then
  3759.   begin
  3760.     { set up the file and open it }
  3761.     AssignFile( TheNewsRCFile , NNTPNGLName );
  3762.     Reset( TheNewsRCFile );
  3763.     { read in the records }
  3764.     for Counter_1 := 0 to FileSize( TheNewsRCFile ) - 1 do
  3765.     begin
  3766.       { Create the TCRecord }
  3767.       New( TheNGRecord );
  3768.       { Read in the data record }
  3769.       Seek( TheNewsRCFile , Counter_1 );
  3770.       Read( TheNewsRCFile , TheNGRecord^ );
  3771.       { Add the record to the list }
  3772.       TheNewsRCList.Add( TheNGRecord );
  3773.     end;
  3774.     { close the file }
  3775.     CloseFile( TheNewsRCFile );
  3776.   end
  3777.   else
  3778.   { Otherwise create a default one with 3 delphi newsgroups }
  3779.   begin
  3780.     { create new record }
  3781.     New( TheNGRecord );
  3782.     { fill in its info }
  3783.     with TheNGRecord^ do
  3784.     begin
  3785.       GName                := 'Delphi Comps';
  3786.       GRealName            := 'comp.lang.pascal.delphi.components';
  3787.       GLowest              := 0;
  3788.       GHighest             := 0;
  3789.       GPostable            := true;
  3790.       GSubscribed          := true;
  3791.       GTotalArticles       := 0;
  3792.       GTotalAvailable      := 0;
  3793.       GLowestAvailable     := 0;
  3794.       GHighestAvailable    := 0;
  3795.       GTotalUnReadArticles := 0;
  3796.       GIDNumber            := 1;
  3797.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G1.NGR';
  3798.       GLTag                := 0;
  3799.     end;
  3800.     { add it to the list }
  3801.     TheNewsRCList.Add( TheNGRecord );
  3802.     { create new record }
  3803.     New( TheNGRecord );
  3804.     { fill in its info }
  3805.     with TheNGRecord^ do
  3806.     begin
  3807.       GName                := 'Delphi DB';
  3808.       GRealName            := 'comp.lang.pascal.delphi.databases';
  3809.       GLowest              := 0;
  3810.       GHighest             := 0;
  3811.       GPostable            := true;
  3812.       GSubscribed          := true;
  3813.       GTotalArticles       := 0;
  3814.       GTotalAvailable      := 0;
  3815.       GLowestAvailable     := 0;
  3816.       GHighestAvailable    := 0;
  3817.       GTotalUnReadArticles := 0;
  3818.       GIDNumber            := 2;
  3819.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G2.NGR';
  3820.       GLTag                := 0;
  3821.     end;
  3822.     { add it to the list }
  3823.     TheNewsRCList.Add( TheNGRecord );
  3824.     { create new record }
  3825.     New( TheNGRecord );
  3826.     { fill in its info }
  3827.     with TheNGRecord^ do
  3828.     begin
  3829.       GName                := 'Delphi Misc';
  3830.       GRealName            := 'comp.lang.pascal.delphi.misc';
  3831.       GLowest              := 0;
  3832.       GHighest             := 0;
  3833.       GPostable            := true;
  3834.       GSubscribed          := true;
  3835.       GTotalArticles       := 0;
  3836.       GTotalAvailable      := 0;
  3837.       GLowestAvailable     := 0;
  3838.       GHighestAvailable    := 0;
  3839.       GTotalUnReadArticles := 0;
  3840.       GIDNumber            := 3;
  3841.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G3.NGR';
  3842.       GLTag                := 0;
  3843.     end;
  3844.     { add it to the list }
  3845.     TheNewsRCList.Add( TheNGRecord );
  3846.     { create the file and write out the data, then close it }
  3847.     AssignFile( TheNewsRCFile , NNTPNGLName );
  3848.     Rewrite( TheNewsRCFile );
  3849.     for Counter_1 := 0 to 2 do
  3850.     begin
  3851.       TheNGRecord :=
  3852.        PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3853.       Seek( TheNewsRCFile , Counter_1 );
  3854.       Write( TheNewsRCFile , TheNGRecord^ );
  3855.     end;
  3856.     CloseFile( TheNewsRCFile );
  3857.   end;
  3858.   { Load in Articles Records and create storage lists }
  3859.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3860.   begin
  3861.     NNTPARName := PNewsGroupRecord(
  3862.      TheNewsRCList.Items[ Counter_1 ] )^.GFileName;
  3863.     if FileExists( NewsPath + '\' + NNTPARName ) then
  3864.     begin
  3865.       TheNGArticlesList := TList.Create;
  3866.       AssignFile( TheNewsArticleFile , NewsPath + '\' + NNTPARName );
  3867.       Reset( TheNewsArticleFile );
  3868.       for Counter_2 := 0 to FileSize( TheNewsArticleFile ) - 1 do
  3869.       begin
  3870.         New( TheNGARecord );
  3871.         Seek( TheNewsArticleFile , Counter_2 );
  3872.         Read( TheNewsArticleFile , TheNGARecord^ );
  3873.         TheNGArticlesList.Add( TheNGARecord );
  3874.       end;
  3875.       CloseFile( TheNewsArticleFile );
  3876.       PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^.GLTag :=
  3877.        Longint( TheNGArticlesList );
  3878.     end
  3879.     else
  3880.     begin
  3881.       TheNGArticlesList := TList.Create;
  3882.       PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^.GLTag :=
  3883.        Longint( TheNGArticlesList );
  3884.     end;
  3885.   end;
  3886.   { Create working Newsgroup list for later }
  3887.   TheWorkingNRCSL := TList.Create;
  3888.   For Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3889.   begin
  3890.     New( TheNGRecord );
  3891.     TheNGRecord^ := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^;
  3892.     TheWorkingNRCSL.Add( TheNGRecord );
  3893.   end;
  3894. end;
  3895.  
  3896. { This procedure populates LB2 with article subjects for any }
  3897. { available articles for a given newsgroup.                  }
  3898. procedure TCCINetCCForm.PopulateLB2WithArticleHeaders;
  3899. var Counter_1    : Integer;
  3900.     TheNGARecord : PNewsGroupArticleRecord;
  3901.     TempString   : String;
  3902. begin
  3903.   { Clear target list box }
  3904.   ListBox2.Clear;
  3905.   for Counter_1 := 0 to TheNGArticlesList.Count - 1 do
  3906.   begin
  3907.     TheNGARecord :=
  3908.      PNewsGroupArticleRecord( TheNGArticlesList.Items[ Counter_1 ] );
  3909.     TempString := '    [' + IntToStr( Counter_1 ) + '] ' +
  3910.      TheNGARecord^.NGASubject;
  3911.     if TheNGARecord^.NGADownloaded then TempString[ 1 ] :=
  3912.      'D';
  3913.     if TheNGARecord^.NGARead then TempString[ 3 ] := 'R';
  3914.     if TheNGARecord^.NGAPosted then TempString[ 3 ] := 'S';
  3915.     ListBox2.Items.Add( TempString );
  3916.   end;
  3917. end;
  3918.  
  3919. { This procedure swaps in the list of subscribed newsgroups to LB1 }
  3920. { and calls another procedure to populate LB2 with any available   }
  3921. { articles for the newsgroup.                                      }
  3922. procedure TCCINetCCForm.SetupNewsGroupListboxes;
  3923. var Counter_1   : Integer;
  3924.     TempString  : String;
  3925.     TheNGRecord : PNewsGroupRecord;
  3926. begin
  3927.   ListBox1.Clear;
  3928.   ListBox1.Tag := 5;
  3929.   ListBox2.Tag := 5;
  3930.   Label4.Caption := 'NewsGroups';
  3931.   Label5.Caption := 'Articles';
  3932.   if TheNewsRCList.Count = 0 then
  3933.   begin
  3934.     ListBox2.Clear;
  3935.     exit;
  3936.   end;
  3937.   ComboBox1.Clear;
  3938.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3939.   begin
  3940.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3941.     TempString := TheNGRecord^.GName;
  3942.     ComboBox1.Items.Add( TheNGRecord^.GRealName );
  3943.     if TheNGRecord^.GSubscribed then
  3944.      TempString := '[S] ' + TempString else TempString := '[U] ' + TempString;
  3945.     TempString := TempString + '{' + IntToStr( TheNGRecord^.GTotalNew ) + '}';
  3946.     ListBox1.Items.Add( TempString );
  3947.   end;
  3948.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ 0 ] );
  3949.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  3950.   PopulateLB2WithArticleHeaders;
  3951.   Label1.Caption := 'NewsGroup:';
  3952.   ComboBox1.ItemIndex := 0;
  3953.   Button1.Caption := 'DL Article(s)';
  3954.   Tag := 5; { Set download vector }
  3955. end;
  3956.  
  3957. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3958. procedure TCCINetCCForm.SetupNNTPServersInfoDisplay;
  3959. var Counter_1  : Integer;            { Loop counter        }
  3960. begin
  3961.   { Set tag for NNTP stuff }
  3962.   CCICInfoDlg.Tag := 4; { Usenet News Tag -- servers }
  3963.   { set up caption of main label }
  3964.   CCICInfoDlg.Label2.Caption := 'News Server Sites';
  3965.   { hide outline panel }
  3966.   CCICInfoDlg.Panel6.Visible := false;
  3967.   CCICInfoDlg.Panel5.Visible := false;
  3968.   CCICInfoDlg.Panel8.Visible := false;
  3969.   CCICInfoDlg.Panel9.Visible := false;
  3970.   { clear the list box }
  3971.   CCICInfoDlg.ListBox2.Clear;
  3972.   CCINetCCForm.ComboBox1.Clear;
  3973.   { add profile strings to the list box }
  3974.   for Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3975.   begin
  3976.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  3977.      TheNewsServerList.Items[ Counter_1 ] )^.CProfile );
  3978.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  3979.      TheNewsServerList.Items[ Counter_1 ] )^.CProfile );
  3980.   end;
  3981.   { Set up caption of special button }
  3982.   CCICInfoDlg.Button1.Visible := false;
  3983.   { Start with top record }
  3984.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  3985.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  3986.   { put in data from top record and reset captions }
  3987.   with PConnectionsRecord( TheNewsServerList.Items[ 0 ] )^ do
  3988.   begin
  3989.     with CCICInfoDlg do
  3990.     begin
  3991.       Edit1.Text := CProfile;
  3992.       Panel2.Caption := '            Name:';
  3993.       Edit2.Text := CIPAddress;
  3994.       Panel3.Caption := '     IP Address:';
  3995.     end;
  3996.   end;
  3997. end;
  3998.  
  3999. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  4000. procedure TCCINetCCForm.SetupNNTPNewsGroupsInfoDisplay;
  4001. var Counter_1  : Integer;            { Loop counter        }
  4002.     WorkingFileName : String;
  4003.     TheWorkingSL : TStringList;
  4004. begin
  4005.   { Set tag for NNTP stuff }
  4006.   CCICInfoDlg.Tag := 5; { Usenet News Tag -- newsgroups }
  4007.   { set up caption of main label }
  4008.   CCICInfoDlg.Label2.Caption := 'Active NewsGroups';
  4009.   { hide outline panel }
  4010.   CCICInfoDlg.Panel5.Visible := true;
  4011.   CCICInfoDlg.Panel6.Visible := true;
  4012.   CCICInfoDlg.Panel6.Height := 224;
  4013.   CCICInfoDlg.Panel6.Top := 120;
  4014.   CCICInfoDlg.Label1.Caption := 'Available NewsGroups';
  4015.   CCICInfoDlg.Panel8.Visible := false;
  4016.   CCICInfoDlg.Panel9.Visible := false;
  4017.   { clear the list box }
  4018.   CCICInfoDlg.ListBox2.Clear;
  4019.   { add profile strings to the list box }
  4020.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  4021.   begin
  4022.     CCICInfoDlg.ListBox2.Items.Add( PNewsGroupRecord(
  4023.      TheNewsRCList.Items[ Counter_1 ] )^.GName );
  4024.   end;
  4025.   { Set up caption of special button }
  4026.   CCICInfoDlg.Button1.Visible := true;
  4027.   CCICInfoDlg.Button1.Caption := 'Toggle Subscription';
  4028.   { Start with top record }
  4029.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  4030.   { put in data from top record and reset captions }
  4031.   with PNewsGroupRecord( TheNewsRCList.Items[ 0 ] )^ do
  4032.   begin
  4033.     with CCICInfoDlg do
  4034.     begin
  4035.       Edit1.Text := GName;
  4036.       Panel2.Caption := 'NG Name:';
  4037.       Edit2.Text := GRealName;
  4038.       Panel3.Caption := 'NG Real Name:';
  4039.       if GSubscribed then
  4040.       Edit3.Text := 'Subscribed' else Edit3.Text := 'UnSubscribed';
  4041.       Panel5.Caption := 'Status:';
  4042.     end;
  4043.   end;
  4044.   if newsgroupListloaded then exit;
  4045.   WorkingFileName := NewsPath + '\NEWSGRP.TXT';
  4046.   if FileExists( WorkingFileName ) then
  4047.   begin
  4048.     if MessageDlg( 'Load News Groups File? (Long operation...)',
  4049.      mtConfirmation,mbYesNoCancel,0) = mrYes then
  4050.     begin
  4051.       CCICInfoDlg.ListBox1.Clear;
  4052.       TheWorkingSL := TStringList.Create;
  4053.       try
  4054.         TheWorkingSL.LoadFromFile( WorkingFileName );
  4055.         CCICInfoDlg.ListBox1.Items.Assign( TheWorkingSL );
  4056.       except
  4057.         MessageDlg( 'News Group List Too Large! Use WordPad/Write to view ' +
  4058.                       NewsPath + '\NEWGRP.TXT' , mtInformation,[mbOK],0);
  4059.         TheWorkingSL.Free;
  4060.         NewsgroupListLoaded := false;
  4061.         exit;
  4062.       end;
  4063.       TheWorkingSL.Free;
  4064.       NewsgroupListLoaded := true;
  4065.     end;
  4066.   end;
  4067. end;
  4068.  
  4069. { This procedure scans a line of UNIX-style text for #10's and }
  4070. { outputs them as lines to the memo. It stops at #0.           }
  4071. procedure TCCINetCCForm.AddNullTermTextToMemo( TheTextToAdd   : String;
  4072.                                  TheMemoToAddTo : TMemo   );
  4073. var
  4074.   TextLength ,            { Total chars to output         }
  4075.   Counter_1    : integer; { Loop Index                    }
  4076. begin
  4077.   { Make the target memo visible just in case }
  4078.   TheMemoToAddTo.Visible := true;
  4079.   { Find total chars to output }
  4080.   TextLength := Length( TheTextToAdd );
  4081.   { If none then leave }
  4082.   if TextLength = 0 then exit;
  4083.   { Loop along the string }
  4084.   for Counter_1 := 1 to TextLength do
  4085.   begin
  4086.     { If hit ASCII 10 then assume end of line and output }
  4087.     if TheTextToAdd[ Counter_1 ] = #10 then
  4088.     begin
  4089.       { Use a try loop incase memo fills up }
  4090.       try
  4091.         { Add the line }
  4092.         TheMemoToAddTo.Lines.Add( TheLine );
  4093.       except
  4094.         { If memo fills up }
  4095.         on EOutOfResources do
  4096.         begin
  4097.           { Clear the old data }
  4098.           TheMemoToAddTo.Clear;
  4099.           { Output the new }
  4100.           TheMemoToAddTo.Lines.Add( TheLine );
  4101.         end;
  4102.       end;
  4103.       { clear the output buffer }
  4104.       TheLine := '';
  4105.     end
  4106.     else
  4107.     { Otherwise look for null terminator from Winsock }
  4108.     begin
  4109.       { If don't hit null terminator then add the char to op buffer }
  4110.       if TheTextToAdd[ Counter_1 ] <> #0 then
  4111.       begin
  4112.         TheLine := TheLine + TheTextToAdd[ Counter_1 ];
  4113.       end
  4114.       else break; { Otherwise drop out of the loop }
  4115.     end;
  4116.   end;
  4117. end;
  4118.  
  4119. { This function scans a line of UNIX-style text for #10's and }
  4120. { outputs the first line as its return value,stopping at #0.  }
  4121. function TCCINetCCForm.AddNullTermTextToLabel( TheTextToAdd   : String ) : String;
  4122. var
  4123.   TheLine      : String;  { Buffer to output current line }
  4124.   TextLength ,            { Total chars to output         }
  4125.   Counter_1    : integer; { Loop Index                    }
  4126. begin
  4127.   { Clear output buffer }
  4128.   TheLine := '';
  4129.   { Find total chars to output }
  4130.   TextLength := Length( TheTextToAdd );
  4131.   { If none then leave }
  4132.   if TextLength = 0 then
  4133.   begin
  4134.     { Return nothing }
  4135.     Result := '';
  4136.     { Leave }
  4137.     exit;
  4138.   end;
  4139.   { Loop along the string }
  4140.   for Counter_1 := 1 to TextLength do
  4141.   begin
  4142.     { If hit ASCII 10 then assume end of line and output }
  4143.     if TheTextToAdd[ Counter_1 ] = #10 then
  4144.     begin
  4145.       { Return first line }
  4146.       Result := TheLine;
  4147.       { Leave }
  4148.       exit;
  4149.     end
  4150.     else
  4151.     { Otherwise look for null terminator from Winsock }
  4152.     begin
  4153.       { If don't hit null terminator then add the char to op buffer }
  4154.       if TheTextToAdd[ Counter_1 ] <> #0 then
  4155.       begin
  4156.         TheLine := TheLine + TheTextToAdd[ Counter_1 ];
  4157.       end
  4158.       else break; { Otherwise drop out of the loop }
  4159.     end;
  4160.   end;
  4161.   { If hit #0 before #10 return buffer }
  4162.   Result := TheLine;
  4163. end;
  4164.  
  4165. { Show busy cursors }
  4166. procedure TCCINetCCForm.SetHGCursors;
  4167. begin
  4168.   CCInetCCForm.Cursor := crHourGlass;
  4169.   CCInetCCForm.Memo1.Cursor := crHourGlass;
  4170. end;
  4171.  
  4172. { Show normal cursors }
  4173. procedure TCCINetCCForm.SetNormalCursors;
  4174. begin
  4175.   CCInetCCForm.Cursor := crDefault;
  4176.   CCInetCCForm.Memo1.Cursor := crDefault;
  4177. end;
  4178.  
  4179. { Exit method }
  4180. procedure TCCINetCCForm.Exit1Click(Sender: TObject);
  4181. begin
  4182.   Close;
  4183. end;
  4184.  
  4185. { This method adds a line to the progress text stringlist  }
  4186. { If an exception occurs, the list is full, and it is auto }
  4187. { saved to the progress text file name, then cleared.      }
  4188. procedure TCCINetCCForm.AddProgressText( WhatText : String );
  4189. begin
  4190.   { Use a try..except loop to catch list overflows }
  4191.   try
  4192.     { Try the normal add }
  4193.     ProgressList.Add( WhatText );
  4194.   except
  4195.     { Any list error is assumed to be a list overflow }
  4196.     on EListError do
  4197.     begin
  4198.       { Save the list to the preset file name }
  4199.       ProgressList.SaveToFile( ProgressFileName );
  4200.       { Clear the list to make more room }
  4201.       ProgressList.Clear;
  4202.       { And redo the add; any further errors will except normally }
  4203.       ProgressList.Add( WhatText );
  4204.     end;
  4205.     { This might happen too! }
  4206.     on EOutOfResources do
  4207.     begin
  4208.       { Save the list to the preset file name }
  4209.       ProgressList.SaveToFile( ProgressFileName );
  4210.       { Clear the list to make more room }
  4211.       ProgressList.Clear;
  4212.       { And redo the add; any further errors will except normally }
  4213.       ProgressList.Add( WhatText );
  4214.     end;
  4215.   end;
  4216. end;
  4217.  
  4218. { This method either adds the progress line to the current memo }
  4219. { or puts it in the status caption at normal colors.            }
  4220. procedure TCCINetCCForm.ShowProgressText( WhatText : String );
  4221. begin
  4222.   { Use the POV to determine where to show progress info }
  4223.   case ProgressOutputVector of
  4224.     POV_MEMO : begin { Output into the memo  }
  4225.                  AddNullTermTextToMemo( WhatText , Memo1 );
  4226.                end;
  4227.     POV_STAT : begin { Output on status line }
  4228.                  { Set panel caption font to black }
  4229.                  Panel1.Font.Color := clBlack;
  4230.                  { Get the first line of text and put in caption }
  4231.                  Panel1.Caption := AddNullTermTextToLabel( WhatText );
  4232.                end;
  4233.   end;
  4234. end;
  4235.  
  4236. { This method is identical with SPT except sets status color to red and beeps }
  4237. procedure TCCINetCCForm.ShowProgressErrorText( WhatText : String );
  4238. begin
  4239.   { Do error beep }
  4240.   MessageBeep( mb_IconExclamation );
  4241.   { Use the POV to determine where to show progress info }
  4242.   case ProgressOutputVector of
  4243.     POV_MEMO : begin { Output into the memo  }
  4244.                  AddNullTermTextToMemo( WhatText , Memo1 );
  4245.                end;
  4246.     POV_STAT : begin { Output on status line }
  4247.                  { Set panel caption font to black }
  4248.                  Panel1.Font.Color := clRed;
  4249.                  { Get the first line of text and put in caption }
  4250.                  Panel1.Caption := AddNullTermTextToLabel( WhatText );
  4251.                end;
  4252.   end;
  4253. end;
  4254.  
  4255. { This is the boilerplate method used to handle Socket errors gracefully }
  4256. procedure TCCINetCCForm.SocketsErrorOccurred( Sender     : TObject;
  4257.                                               ErrorCode  : Integer;
  4258.                                               TheMessage : String   );
  4259. begin
  4260.   { Set the global error code flag }
  4261.   GlobalErrorCode := ErrorCode;
  4262.   { If a timeout error }
  4263.   if ErrorCode = WSAETIMEDOUT then
  4264.   begin
  4265.     { Set the aborted flag }
  4266.     GlobalAbortedFlag := True;
  4267.     { But clear the error code for graceful handling }
  4268.     GlobalErrorCode := 0;
  4269.   end
  4270.   else
  4271.   begin
  4272.     { Otherwise set the progress buffer to the error message }
  4273.     AddProgressText( TheMessage );
  4274.     { And show the progress text as set by option }
  4275.     ShowProgressErrorText( TheMessage );
  4276.   end;
  4277. end;
  4278.  
  4279. procedure TCCINetCCForm.FormCreate(Sender: TObject);
  4280. begin
  4281.   { Create the progress string list }
  4282.   ProgressList := TStringList.Create;
  4283.   { Create the file name for saving the progress list }
  4284.   ProgressFileName := ExpandFileName( 'PROGRESS.TXT' );
  4285.   { Default progress output to status line }
  4286.   ProgressOutputVector := POV_STAT;
  4287.   { Set password control stuff }
  4288.   PasswordControlVector := 2;
  4289.   CurrentPasswordString := 'guest@nowhere.com';
  4290.   CurrentRealPWString := 'guest@nowhere.com';
  4291.   NewMessageInProgress := false;
  4292.   EmailLoaded := false;
  4293.   NewsGroupListLoaded := false;
  4294.   { Get Ini file Data }
  4295.   ReadIniData;
  4296.   LoadFTPSiteFile;
  4297.   LoadNNTPSiteFile;
  4298.   LoadEMailServerFile;
  4299.   TheFTPComponent := TFTPComponent.Create( CCInetCCForm );
  4300.   TheFTPComponent.Parent := CCInetCCForm;
  4301.   TheNNTPComponent := TNNTPComponent.Create( CCInetCCForm );
  4302.   TheNNTPComponent.Parent := CCInetCCForm;
  4303.   ThePOP3SMTPComponent := TPOP3SMTPComponent.Create( CCInetCCForm );
  4304.   ThePOP3SMTPComponent.Parent := CCInetCCForm;
  4305.   TheUUObject := TUUCodingObject.Create( Self );
  4306.   TheUUObject.Parent := self;
  4307.   TheMIMEObject := TMIMECodingObject.Create( Self );
  4308.   TheMIMEObject.Parent := self;
  4309. end;
  4310.  
  4311. procedure TCCINetCCForm.FormDestroy(Sender: TObject);
  4312. begin
  4313.   { Free the progress text stringlist if assigned }
  4314.   if assigned( ProgressList ) then ProgressList.Free;
  4315.   { Save off the Ini data }
  4316.   WriteIniData;
  4317.   { Save and remove FTP site list stuff }
  4318.   SaveFTPSiteFile;
  4319.   SaveNNTPSiteFile;
  4320.   SaveEmailServerFile;
  4321.   if Assigned( TheFTPComponent ) then TheFTPComponent.Free;
  4322.   if Assigned( TheNNTPComponent ) then TheNNTPComponent.Free;
  4323.   if Assigned( ThePOP3SMTPComponent ) then ThePOP3SMTPComponent.Free;
  4324.   if Assigned( TheUUObject ) then TheUUObject.Free;
  4325.   if Assigned( TheMIMEObject ) then TheMIMEObject.Free;
  4326. end;
  4327.  
  4328. procedure TCCINetCCForm.Description1Click(Sender: TObject);
  4329. var
  4330.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4331.   TheData    : String;    { Holder for data                           }
  4332. begin
  4333.   { Create socket; auto calls WSAStartup }
  4334.   TempSocket := TCCSocket.Create( Self );
  4335.   { Do parent just for kicks; no longer needed }
  4336.   TempSocket.Parent := self;
  4337.   { Put in error handler }
  4338.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4339.   TheData := StrPas( TempSocket.Socket_WSA_Data.Description_String );
  4340.   { Display the Description String }
  4341.   AddProgressText( TheData );
  4342.   { And show the progress text as set by option }
  4343.   ShowProgressText( TheData );
  4344.   { Free the socket; auto calls WSACleanup }
  4345.   TempSocket.Free;
  4346. end;
  4347.  
  4348. procedure TCCINetCCForm.SystemStatus1Click(Sender: TObject);
  4349. var
  4350.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4351.   TheData    : String;    { Holder for data                           }
  4352. begin
  4353.   { Create socket; auto calls WSAStartup }
  4354.   TempSocket := TCCSocket.Create( Self );
  4355.   { Do parent just for kicks; no longer needed }
  4356.   TempSocket.Parent := self;
  4357.   { Put in error handler }
  4358.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4359.   TheData := StrPas( TempSocket.Socket_WSA_Data.System_Status_String );
  4360.   { Display the Description String }
  4361.   AddProgressText( TheData );
  4362.   { And show the progress text as set by option }
  4363.   ShowProgressText( TheData );
  4364.   { Free the socket; auto calls WSACleanup }
  4365.   TempSocket.Free;
  4366. end;
  4367.  
  4368. procedure TCCINetCCForm.VendorSpecific1Click(Sender: TObject);
  4369. var
  4370.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4371.   TheData    : String;    { Holder for data                           }
  4372. begin
  4373.   { Create socket; auto calls WSAStartup }
  4374.   TempSocket := TCCSocket.Create( Self );
  4375.   { Do parent just for kicks; no longer needed }
  4376.   TempSocket.Parent := self;
  4377.   { Put in error handler }
  4378.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4379.   TheData := StrPas( TempSocket.Socket_WSA_Data.Vendor_Specific_String );
  4380.   { Display the Description String }
  4381.   AddProgressText( TheData );
  4382.   { And show the progress text as set by option }
  4383.   ShowProgressText( TheData );
  4384.   { Free the socket; auto calls WSACleanup }
  4385.   TempSocket.Free;
  4386. end;
  4387.  
  4388. { This method sets the progress output vector to the memo }
  4389. procedure TCCINetCCForm.ViewInEditWindow1Click(Sender: TObject);
  4390. begin
  4391.   { Set the vector }
  4392.   ProgressOutputVector := POV_MEMO;
  4393.   { Keep the menu options consistent }
  4394.   ViewInEditWindow1.Checked := true;
  4395.   ViewInStatusLine1.Checked := false;
  4396. end;
  4397.  
  4398. { This method sets the progress output vector to the status line }
  4399. procedure TCCINetCCForm.ViewInStatusLine1Click(Sender: TObject);
  4400. begin
  4401.   { Set the vector }
  4402.   ProgressOutputVector := POV_STAT;
  4403.   { Keep the menus consistent }
  4404.   ViewInEditWindow1.Checked := false;
  4405.   ViewInStatusLine1.Checked := true;
  4406. end;
  4407.  
  4408. procedure TCCINetCCForm.SaveToFile1Click(Sender: TObject);
  4409. begin
  4410.   { Set up the dialog parameters }
  4411.   OpenDialog1.Filename := ProgressFileName;
  4412.   OpenDialog1.Title := 'Select Filename for Progress File';
  4413.   OpenDialog1.Filter := 'Text Files|*.txt';
  4414.   { If the dialog is not cancelled then save and clear }
  4415.   if OpenDialog1.Execute then
  4416.   begin
  4417.     ProgressFileName := OpenDialog1.FileName;
  4418.     ProgressList.SaveToFile( ProgressFileName );
  4419.     ProgressList.Clear;
  4420.   end;
  4421. end;
  4422.  
  4423. procedure TCCINetCCForm.IPAddress1Click(Sender: TObject);
  4424. begin
  4425.   { Set up info dialog for IP Address getting }
  4426.   CCICInfoDlg.Caption := 'CC Internet Center -- Translate IP Address';
  4427.   CCICInfoDlg.Panel4.Visible := false;
  4428.   CCICInfoDlg.Panel6.Visible := false;
  4429.   CCICInfoDlg.Panel9.Visible := false;
  4430.   CCICInfoDlg.Panel8.Visible := false;
  4431.   CCICInfoDlg.BitBtn2.Visible := false;
  4432.   CCICInfoDlg.Button1.Caption := 'Get IP Address';
  4433.   CCICInfoDlg.Button2.Visible := false;
  4434.   CCICInfoDlg.Button3.Visible := false;
  4435.   CCICInfoDlg.Button4.Visible := false;
  4436.   CCICInfoDlg.Panel2.Caption := 'IP Addr Name:';
  4437.   CCICInfoDlg.Panel3.Caption := '    Dotted Dec:';
  4438.   CCICInfoDlg.Panel5.Caption := '           Binary:';
  4439.   CCICInfoDlg.Edit1.Text := '';
  4440.   CCICInfoDlg.Edit2.Text := '';
  4441.   CCICInfoDlg.Edit3.Text := '';
  4442.   { Set IP Address Mode }
  4443.   CCICInfoDlg.Tag := 1;
  4444.   { Show Modally to get the information }
  4445.   CCICInfoDlg.ShowModal;
  4446.   { Reset the info dialog to default conditions }
  4447.   CCICInfoDlg.Caption := 'CC Internet Command Center Information Dialog';
  4448.   CCICInfoDlg.Panel4.Visible := true;
  4449.   CCICInfoDlg.Panel6.Visible := true;
  4450.   CCICInfoDlg.Panel9.Visible := true;
  4451.   CCICInfoDlg.Panel8.Visible := true;
  4452.   CCICInfoDlg.BitBtn2.Visible := true;
  4453.   CCICInfoDlg.Button1.Caption := 'Anonymous Login';
  4454.   CCICInfoDlg.Button2.Visible := true;
  4455.   CCICInfoDlg.Button3.Visible := true;
  4456.   CCICInfoDlg.Button4.Visible := true;
  4457.   CCICInfoDlg.Panel2.Caption := '             Name:';
  4458.   CCICInfoDlg.Panel3.Caption := '    IP Address:';
  4459.   CCICInfoDlg.Panel5.Caption := ' User Name:';
  4460.   CCICInfoDlg.Edit1.Text := '';
  4461.   CCICInfoDlg.Edit2.Text := '';
  4462.   CCICInfoDlg.Edit3.Text := '';
  4463. end;
  4464.  
  4465. procedure TCCINetCCForm.FTP1Click(Sender: TObject);
  4466. begin
  4467.   { Set up the FTP Data displays }
  4468.   SetupFTPSiteLists;
  4469.   ListBox1.Clear;
  4470.   ListBox2.Clear;
  4471. end;
  4472.  
  4473. procedure TCCINetCCForm.FormResize(Sender: TObject);
  4474. begin
  4475.   { Use tag vector to determine what to do }
  4476.   case Tag of
  4477.     { if FTP , make sure two list boxes are same height }
  4478.     2 : begin
  4479.           Panel6.Height := (( Panel4.Height div 2 ) - 30 );
  4480.           Panel4.Width := 185;
  4481.         end;
  4482.     4 : begin
  4483.           Panel6.Height := 118;
  4484.           Panel4.Width := 250;
  4485.         end;
  4486.   end;
  4487. end;
  4488.  
  4489. procedure TCCINetCCForm.FTPSites1Click(Sender: TObject);
  4490. begin
  4491.   { Show Modally to get the information }
  4492.   CCICInfoDlg.ShowModal;
  4493. end;
  4494.  
  4495. procedure TCCINetCCForm.FTP3Click(Sender: TObject);
  4496. begin
  4497.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 1;
  4498.   CCICPrefsDlg.Tag := 2;
  4499.   CCICPrefsDlg.ShowModal;
  4500. end;
  4501.  
  4502. procedure TCCINetCCForm.ConnectToSite1Click(Sender: TObject);
  4503. var Counter_1 : Integer;
  4504. begin
  4505.   if Lowercase( PConnectionsRecord( TheFTPSiteList.Items[
  4506.    ComboBox1.ItemIndex ] )^.CUserName ) = 'anonymous' then
  4507.   begin
  4508.     for Counter_1 := 1 to TheAnonRedialVector do
  4509.     begin
  4510.       DoFTPConnection( PConnectionsRecord(
  4511.          TheFTPSiteList.Items[ ComboBox1.ItemIndex ] ));
  4512.       if TheFTPComponent.Connection_Established then exit;
  4513.     end;
  4514.   end
  4515.   else DoFTPConnection( PConnectionsRecord(
  4516.    TheFTPSiteList.Items[ ComboBox1.ItemIndex ] ));
  4517. end;
  4518.  
  4519. procedure TCCINetCCForm.Button1Click(Sender: TObject);
  4520. begin
  4521.   case Tag of
  4522.     2 : begin
  4523.           if not TheFTPComponent.Connection_Established then
  4524.            ConnectToSite1Click( Self ) else
  4525.            begin
  4526.              DoFTPDisconnect;
  4527.              TheFTPComponent.Connection_Established := false;
  4528.              DisableFTPMenus;
  4529.            end;
  4530.         end;
  4531.     4 : begin
  4532.           ConnectAndUpdate1Click( Self );
  4533.         end;
  4534.     5 : begin
  4535.           GetMarked1Click( Self );
  4536.         end;
  4537.     6 : begin
  4538.            CheckMail1Click( Self );
  4539.         end;
  4540.   end;
  4541. end;
  4542.  
  4543. procedure TCCINetCCForm.ViewasText1Click(Sender: TObject);
  4544. begin
  4545.   { Assume valid FTP component and have it send its text into the progress text}
  4546.   TheFTPComponent.GetRemoteDirectoryListingToMemo;
  4547. end;
  4548.  
  4549. procedure TCCINetCCForm.Disconnect1Click(Sender: TObject);
  4550. begin
  4551.   DoFTPDisconnect;
  4552.   DisableFTPMenus;
  4553. end;
  4554.  
  4555. procedure TCCINetCCForm.EnableFTPMenus;
  4556. begin
  4557.   Button1.Caption := 'Disconnect';
  4558.   ConnectToSite1.Enabled := false;
  4559.   Disconnect1.Enabled := true;
  4560.   Directory1.Enabled := true;
  4561.   UploadMarked1.Enabled := true;
  4562.   DownloadMarked1.Enabled := true;
  4563. end;
  4564.  
  4565. procedure TCCINetCCForm.DisableFTPMenus;
  4566. begin
  4567.   Button1.Caption := 'Connect';
  4568.   ConnectToSite1.Enabled := true;
  4569.   Disconnect1.Enabled := false;
  4570.   Directory1.Enabled := false;
  4571.   UploadMarked1.Enabled := false;
  4572.   DownloadMarked1.Enabled := false;
  4573.   FTP1.Enabled := true;
  4574.   UseNetNws1.Enabled := true;
  4575.   IPAddress1.Enabled := true;
  4576.   FTP2.Enabled := false;
  4577. end;
  4578.  
  4579. procedure TCCINetCCForm.EnableNNTPMenus;
  4580. begin
  4581.   Button1.Caption := 'Disconnect';
  4582.   ConnectAndUpdate1.Enabled := false;
  4583.   Disconnect2.Enabled := true;
  4584.   CheckNewNews1.Enabled := true;
  4585.   GetMarked1.Enabled := true;
  4586.   Article1.Enabled := true;
  4587.   Post1.Enabled := true;
  4588.   SubScribedNewsgroups1.Enabled := true;
  4589.   Trash1.Enabled := true;
  4590.   Headers1.Enabled := true;
  4591.   DownLoadActiveNewsGroups1.Enabled := true;
  4592. end;
  4593.  
  4594. procedure TCCINetCCForm.DisableNNTPMenus;
  4595. begin
  4596.   Button1.Caption := 'Connect';
  4597.   ConnectAndUpdate1.Enabled := True;
  4598.   Disconnect2.Enabled := false;
  4599.   CheckNewNews1.Enabled := false;
  4600.   GetMarked1.Enabled := false;
  4601.   Article1.Enabled := false;
  4602.   Post1.Enabled := false;
  4603.   SubScribedNewsgroups1.Enabled := false;
  4604.   Trash1.Enabled := false;
  4605.   Headers1.Enabled := false;
  4606.   DownLoadActiveNewsGroups1.Enabled := false;
  4607. end;
  4608.  
  4609. procedure TCCINetCCForm.ToDisplay1Click(Sender: TObject);
  4610. var Counter_1 : Integer;
  4611. begin
  4612.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4613.   begin
  4614.     if Listbox1.Selected[ Counter_1 ] then
  4615.     begin
  4616.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4617.       TheFTPComponent.
  4618.        ReceiveASCIIRemoteFileToMemo( Listbox1.Items[ Counter_1 ] );
  4619.     end;
  4620.   end;
  4621. end;
  4622.  
  4623. procedure TCCINetCCForm.ToFile1Click(Sender: TObject);
  4624. var Counter_1 : Integer;
  4625.     W16Name   : String;
  4626. begin
  4627.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4628.   begin
  4629.     if Listbox1.Selected[ Counter_1 ] then
  4630.     begin
  4631.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4632.       W16Name := TheFTPComponent.GetWin16Filename( FileNameToXFer );
  4633.       TheFTPComponent.
  4634.        ReceiveASCIIRemoteFile( Listbox1.Items[ Counter_1 ] , W16Name );
  4635.     end;
  4636.   end;
  4637. end;
  4638.  
  4639. procedure TCCINetCCForm.Binary2Click(Sender: TObject);
  4640. var Counter_1 : Integer;
  4641.     W16Name   : String;
  4642. begin
  4643.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4644.   begin
  4645.     if Listbox1.Selected[ Counter_1 ] then
  4646.     begin
  4647.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4648.       W16Name := TheFTPComponent.GetWin16Filename( FileNameToXFer );
  4649.       TheFTPComponent.
  4650.        ReceiveBinaryRemoteFile( Listbox1.Items[ Counter_1 ] , W16Name );
  4651.     end;
  4652.   end;
  4653. end;
  4654.  
  4655. procedure TCCINetCCForm.Change1Click(Sender: TObject);
  4656. var TheDir : String;
  4657. begin
  4658.   if ListBox1.ItemIndex = -1 then exit;
  4659.   TheDir := ListBox1.Items[ ListBox1.ItemIndex ];
  4660.   if TheFTPComponent.SetRemoteDirectory( TheDir ) then
  4661.   begin
  4662.     TheFTPComponent.GetRemoteWorkingDirectory( TheDir ); 
  4663.     { Put up remote directory via PWD and strip quotes }
  4664.     Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4665.     { Get the listings of directories and exit OK }
  4666.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4667.   end;
  4668. end;
  4669.  
  4670. procedure TCCINetCCForm.ChangeLocal1Click(Sender: TObject);
  4671. var TheDir : String;
  4672. begin
  4673.   if ListBox2.ItemIndex = -1 then exit;
  4674.   TheDir := ListBox2.Items[ ListBox2.ItemIndex ];
  4675.   TheDir := TheFTPComponent.StripBrackets( TheDir );
  4676.   if TheDir = '..' then
  4677.   begin
  4678.     ChDir( TheDir );
  4679.   end
  4680.   else
  4681.   begin
  4682.     TheDir := ExpandFileName( TheDir );
  4683.     ChDir( TheDir );
  4684.   end;
  4685.   TheFTPComponent.GetLocalDirectoryAndListing( TheDir , Listbox2 );
  4686.   if Label5.Canvas.TextWidth( TheDir ) > Label5.Width then
  4687.    TheDir := TheFTPComponent.GetShortPathName( TheDir );
  4688.   Label5.Caption := TheDir;
  4689. end;
  4690.  
  4691. procedure TCCINetCCForm.ListBox1DblClick(Sender: TObject);
  4692. begin
  4693.   case Tag of
  4694.     2 : begin
  4695.           case DefaultDownLoadVector of
  4696.             1 : Binary2Click( Self );
  4697.             2 : ToFile1Click( Self );
  4698.             3 : Change1Click( Self );
  4699.           end;
  4700.         end;
  4701.   end;
  4702. end;
  4703.  
  4704. procedure TCCINetCCForm.ListBox2DblClick(Sender: TObject);
  4705. var WorkingString ,
  4706.     NumberString    : String;
  4707.     TheIDNumber     : Integer;
  4708.     TheNGARecord    : PNewsGroupArticleRecord;
  4709. begin
  4710.   case Tag of
  4711.     2 : begin
  4712.           case DefaultDownLoadVector of
  4713.             1 : Binary1Click( Self );
  4714.             2 : ASCII1Click( Self );
  4715.             3 : ChangeLocal1Click( Self );
  4716.           end;
  4717.         end;
  4718.     5 : begin
  4719.           if ListBox2.Tag <> 5 then exit;
  4720.           if ListBox2.ItemIndex = -1 then exit;
  4721.           WorkingString := ListBox2.Items[ ListBox2.ItemIndex ];
  4722.           NumberString := TheFTPComponent.StripBrackets( WorkingString );
  4723.           TheIDNumber := StrToInt( NumberString );
  4724.           TheNGARecord := PNewsGroupArticleRecord(
  4725.            TheNGArticlesList.Items[ TheIDNumber ] );
  4726.           if TheNGARecord^.NGADownloaded then
  4727.           begin
  4728.             Memo1.Clear;
  4729.             try
  4730.               Memo1.Lines.LoadFromFile( NewsPath + '\' + TheNGARecord^.NGAArtFileName );
  4731.             except
  4732.               MessageDlg( 'Article Too Large to Load! Use Write to View [' +
  4733.                TheNGARecord^.NGAArtFilename + '.',
  4734.                mtError,[mbOK],0);
  4735.               exit;
  4736.             end;
  4737.             Label1.Caption := 'Subject:';
  4738.             ComboBox1.Text := TheNGARecord^.NGASubject;
  4739.             TheNGARecord^.NGARead := true;
  4740.             WorkingString := ListBox2.Items[ ListBox2.ItemIndex ];
  4741.             WorkingString[ 3 ] := 'R';
  4742.             ListBox2.Items[ ListBox2.ItemIndex ] := WorkingString;
  4743.           end
  4744.           else
  4745.           begin
  4746.             MessageDlg( 'Article Not Downloaded!',mtError,[mbOK],0);
  4747.           end;
  4748.         end;
  4749.     6 : begin
  4750.           if ListBox2.ItemIndex = -1 then exit;
  4751.           WorkingString := PEMailMessageRecord(
  4752.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRFileName;
  4753.           PEMailMessageRecord(
  4754.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRRead := true;;
  4755.           WorkingString := MailPath + '\' + WorkingString;
  4756.           Memo1.Clear;
  4757.           try
  4758.             Memo1.Lines.LoadFromFile( WorkingString );
  4759.           except
  4760.             MessageDlg( 'Article Too Large to Load! Use Write to View.',
  4761.              mtError,[mbOK],0);
  4762.             exit;
  4763.           end;
  4764.           Label1.Caption := 'Subject:';
  4765.           ComboBox1.Text := PEMailMessageRecord(
  4766.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRMessageSubject;
  4767.           PopulateLB2WithMessageHeaders;
  4768.         end;
  4769.   end;
  4770. end;
  4771.  
  4772. procedure TCCINetCCForm.ASCII1Click(Sender: TObject);
  4773. var Counter_1 : Integer;
  4774.     TheDir    : String;
  4775. begin
  4776.   for Counter_1 := 0 to Listbox2.Items.Count - 1 do
  4777.   begin
  4778.     if Listbox2.Selected[ Counter_1 ] then
  4779.     begin
  4780.       FileNameToXFer := ListBox2.Items[ Counter_1 ];
  4781.       TheFTPComponent.
  4782.        SendASCIILocalFile( Listbox2.Items[ Counter_1 ] );
  4783.     end;
  4784.   end;
  4785.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4786.   { Put up remote directory via PWD and strip quotes }
  4787.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4788.   { Get the listings of directories and exit OK }
  4789.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4790. end;
  4791.  
  4792. procedure TCCINetCCForm.DeleteRemoteFiles1Click(Sender: TObject);
  4793. var Counter_1 : Integer;
  4794.     TheDir    : String;
  4795.     DoAll     : Boolean;
  4796.     TheResult : Integer;
  4797. begin
  4798.   DoAll := false;
  4799.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4800.   begin
  4801.     if Listbox1.Selected[ Counter_1 ] then
  4802.     begin
  4803.       if not DoAll then
  4804.       begin
  4805.         TheResult := MessageDlg( 'Delete Remote File ' +
  4806.          ListBox1.Items[ Counter_1 ] + ' ?',mtConfirmation,
  4807.           [mbYes,mbNo,mbCancel,mbAll],0 );
  4808.         case TheResult of
  4809.           mrYes : ;
  4810.           mrNo  : ;
  4811.           mrCancel : break;
  4812.           mrAll : begin
  4813.                     TheResult := mrYes;
  4814.                     DoAll := true;
  4815.                   end;
  4816.         end;
  4817.       end
  4818.       else TheResult := mrYes;
  4819.       if TheResult = mrYes then TheFTPComponent.
  4820.          DeleteRemoteFile( Listbox1.Items[ Counter_1 ] );
  4821.     end;
  4822.   end;
  4823.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4824.   { Put up remote directory via PWD and strip quotes }
  4825.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4826.   { Get the listings of directories and exit OK }
  4827.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4828. end;
  4829.  
  4830. procedure TCCINetCCForm.Binary1Click(Sender: TObject);
  4831. var Counter_1 : Integer;
  4832.     TheDir    : String;
  4833. begin
  4834.   for Counter_1 := 0 to Listbox2.Items.Count - 1 do
  4835.   begin
  4836.     if Listbox2.Selected[ Counter_1 ] then
  4837.     begin
  4838.       FileNameToXFer := ListBox2.Items[ Counter_1 ];
  4839.       TheFTPComponent.
  4840.        SendBinaryLocalFile( Listbox2.Items[ Counter_1 ] );
  4841.     end;
  4842.   end;
  4843.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4844.   { Put up remote directory via PWD and strip quotes }
  4845.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4846.   { Get the listings of directories and exit OK }
  4847.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4848. end;
  4849.  
  4850. procedure TCCINetCCForm.Delete3Click(Sender: TObject);
  4851. var Counter_1 : Integer;
  4852.     TheDir    : String;
  4853. begin
  4854.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4855.   begin
  4856.     if Listbox1.Selected[ Counter_1 ] then
  4857.     begin
  4858.       if ListBox1.Items[ Counter_1 ] <> '..' then
  4859.        TheFTPComponent.
  4860.         DeleteRemoteDirectory( Listbox1.Items[ Counter_1 ] );
  4861.     end;
  4862.   end;
  4863.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4864.   { Put up remote directory via PWD and strip quotes }
  4865.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4866.   { Get the listings of directories and exit OK }
  4867.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4868. end;
  4869.  
  4870. procedure TCCINetCCForm.Create1Click(Sender: TObject);
  4871. var TheDir : String;
  4872. begin
  4873.   OpenDialog1.Filename := '*.*';
  4874.   OpenDialog1.Title := 'Enter Remote Directory Name';
  4875.   if OpenDialog1.Execute then
  4876.   begin
  4877.     TheFTPComponent.
  4878.      CreateRemoteDirectory( ExtractFileName( OpenDialog1.FileName ));
  4879.     TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4880.     { Put up remote directory via PWD and strip quotes }
  4881.     Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4882.     { Get the listings of directories and exit OK }
  4883.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4884.   end;
  4885. end;
  4886.  
  4887. procedure TCCINetCCForm.ListBox1Click(Sender: TObject);
  4888. var TheNGRecord : PNewsGroupRecord;
  4889.     TheMBRecord : PEMailMailboxRecord;
  4890. begin
  4891.   case ListBox1.Tag of
  4892.     5 : begin
  4893.           if ListBox1.ItemIndex = -1 then exit;
  4894.           TheNGRecord :=
  4895.            PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  4896.           TheNGArticlesList := TList( TheNGRecord^.GLTag );
  4897.           PopulateLB2WithArticleHeaders;
  4898.           ComboBox1.ItemIndex := ListBox1.ItemIndex;
  4899.         end;
  4900.     6 : begin
  4901.           if ListBox1.ItemIndex = -1 then exit;
  4902.           TheMBRecord :=
  4903.            PEMailMailboxRecord( TheEMailMailboxList.Items[ ListBox1.ItemIndex ] );
  4904.           TheMBMessagesList := TList( TheMBRecord^.MBLTag );
  4905.           PopulateLB2WithMessageHeaders;
  4906.         end;
  4907.   end;
  4908. end;
  4909.  
  4910. procedure TCCINetCCForm.UsenetNws1Click(Sender: TObject);
  4911. begin
  4912.   if TheFTPComponent.Connection_Established then
  4913.   begin
  4914.     MessageDlg( 'Must disconnect from current FTP session first!',
  4915.      mtError,[mbOK],0);
  4916.     exit;
  4917.   end;
  4918.   { Show The NNTP servers display }
  4919.   ListBox1.Clear;
  4920.   ListBox2.Clear;
  4921.   SetupNNTPSiteLists;
  4922.   NewsGroupListLoaded := false;
  4923.   SetupNNTPServersInfoDisplay;
  4924. end;
  4925.  
  4926. procedure TCCINetCCForm.Disconnect2Click(Sender: TObject);
  4927. begin
  4928.   SaveNNTPNewsGroupLists;
  4929.   DoNNTPDisconnect;
  4930.   DisableNNTPMenus;
  4931.   ListBox1.Clear;
  4932.   ListBox2.Clear;
  4933. end;
  4934.  
  4935. procedure TCCINetCCForm.News2Click(Sender: TObject);
  4936. begin
  4937.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 2;
  4938.   CCICPrefsDlg.Tag := 4;
  4939.   CCICPrefsDlg.ShowModal;
  4940. end;
  4941.  
  4942. procedure TCCINetCCForm.ConnectandUpdate1Click(Sender: TObject);
  4943. begin
  4944.   DoNNTPConnection( PConnectionsRecord(
  4945.      TheNewsServerList.Items[ ComboBox1.ItemIndex ] ));
  4946.   if TheNNTPComponent.Connection_Established then
  4947.   begin
  4948.     SetupNNTPNewsGroupLists;
  4949.     if NewsInitialUpdateVector = 1 then
  4950.     begin { Update all active newsgroups }
  4951.       TheNNTPComponent.CheckAllNewNews;
  4952.     end;
  4953.     { Bring up the files with current NG information }
  4954.     SetupNewsGroupListboxes;
  4955.   end;
  4956. end;
  4957.  
  4958. procedure TCCINetCCForm.CheckNewNews1Click(Sender: TObject);
  4959. begin
  4960.   TheNNTPComponent.CheckAllNewNews;
  4961.   SetupNewsGroupListboxes;
  4962. end;
  4963.  
  4964. procedure TCCINetCCForm.NewsServers1Click(Sender: TObject);
  4965. begin
  4966.   { Reset display to NNTP Servers }
  4967.   SetupNNTPServersInfoDisplay;
  4968.   { Show Modally to get the information }
  4969.   CCICInfoDlg.ShowModal;
  4970. end;
  4971.  
  4972. procedure TCCINetCCForm.SubscribedNewsgroups1Click(Sender: TObject);
  4973. begin
  4974.   { Reset display to Usenet Newsgroups }
  4975.   SetupNNTPNewsGroupsInfoDisplay;
  4976.   { Show Modally to get the information }
  4977.   CCICInfoDlg.ShowModal;
  4978.   TheNNTPComponent.CheckAllNewNews;
  4979.   SetupNewsGroupListboxes;
  4980. end;
  4981.  
  4982. procedure TCCINetCCForm.RetrieveMarked1Click(Sender: TObject);
  4983. var Counter_1   : Integer;
  4984.     TheNGRecord : PNewsGroupRecord;
  4985. begin
  4986.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  4987.   begin
  4988.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  4989.     if (( TheNGRecord^.GSubscribed ) and ( ListBox1.Selected[ Counter_1 ] )) then
  4990.     begin
  4991.       TheNNTPComponent.GetAllArticleHeaders( TheNGRecord );
  4992.     end;
  4993.   end;
  4994.   SetupNewsGroupListboxes;
  4995. end;
  4996.  
  4997. procedure TCCINetCCForm.RetrieveAll1Click(Sender: TObject);
  4998. var Counter_1   : Integer;
  4999.     TheNGRecord : PNewsGroupRecord;
  5000. begin
  5001.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  5002.   begin
  5003.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5004.     if TheNGRecord^.GSubscribed then
  5005.     begin
  5006.       TheNNTPComponent.GetAllArticleHeaders( TheNGRecord );
  5007.     end;
  5008.   end;
  5009.   SetupNewsGroupListboxes;
  5010. end;
  5011.  
  5012. procedure TCCINetCCForm.GetMarked1Click(Sender: TObject);
  5013. var TheNGRecord : PNewsGroupRecord;
  5014. begin
  5015.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5016.   TheNNTPComponent.DownloadAllMarkedArticleListings( TheNGRecord , ListBox2 );
  5017.   SetupNewsGroupListboxes;
  5018. end;
  5019.  
  5020. procedure TCCINetCCForm.NewArticle1Click(Sender: TObject);
  5021. begin
  5022.   if ListBox1.ItemIndex = -1 then exit;
  5023.   Memo1.Clear;
  5024.   TheNNTPComponent.SetNewsHeaders( Memo1 , ListBox1.ItemIndex );
  5025. end;
  5026.  
  5027. procedure TCCINetCCForm.FollowupArticle1Click(Sender: TObject);
  5028. begin
  5029.   if ListBox1.ItemIndex = -1 then exit;
  5030.   if ListBox2.ItemIndex = -1 then exit;
  5031.   Memo1.Clear;
  5032.   TheNNTPComponent.SetFUNewsHeaders( Memo1              ,
  5033.                                      ListBox1.ItemIndex ,
  5034.                                      ListBox2.ItemIndex   );
  5035. end;
  5036.  
  5037. procedure TCCINetCCForm.PutinQueue1Click(Sender: TObject);
  5038. var TheNGRecord : PNewsGroupRecord;
  5039.     TheNGARecord : PNewsGroupArticleRecord;
  5040.     WorkingList : TList;
  5041.     WorkingFilename : String;
  5042.     Holdingposition : Integer;
  5043. begin
  5044.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5045.   WorkingList := TList( TheNGRecord^.GLTag );
  5046.   New( TheNGARecord );
  5047.   with TheNGARecord^ do
  5048.   begin
  5049.     NGAGroupname   := TheNGRecord^.GRealName;
  5050.     NGASubject     := TheNNTPComponent.GetHeaderSubject( TStringList( Memo1.Lines ));
  5051.     NGANumber      := TheNGRecord^.GHighestAvailable + WorkingList.Count;
  5052.     NGADownloaded  := true;
  5053.     NGASender      := 'CIUPKC158';
  5054.     NGARead        := false;
  5055.     NGAPosted      := false;
  5056.     WorkingFileName := 'AR' + IntToStr( NGANumber );
  5057.     if Length( WorkingFileName ) > 8 then
  5058.      WorkingFileName := Copy( WorkingFileName ,1 , 8 );
  5059.     WorkingFileName := WorkingFileName + '.' + IntToStr( TheNGRecord^.GIDNumber );
  5060.     NGAArtFileName := WorkingFileName;
  5061.   end;
  5062.   WorkingList.Add( TheNGARecord );
  5063.   Memo1.Lines.SaveToFile( NewsPath + '\' + WorkingFileName );
  5064.   HoldingPosition := ListBox1.itemindex;
  5065.   SetupNewsGroupListboxes;
  5066.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ HoldingPosition ] );
  5067.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  5068.   PopulateLB2WithArticleHeaders;
  5069. end;
  5070.  
  5071. procedure TCCINetCCForm.CurrentArticle1Click(Sender: TObject);
  5072. var TheNGARecord : PNewsGroupArticleRecord;
  5073.     TheNGRecord  : PNewsGroupRecord;
  5074.     HP : Integer;
  5075. begin
  5076.   HP := ListBox1.itemindex;
  5077.   PutInQueue1Click( Self );
  5078.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ HP ] );
  5079.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  5080.   TheNGARecord := PNewsGroupArticleRecord( TheNGArticlesList.Items[ TheNGArticlesList.Count - 1 ] );
  5081.   TheNNTPComponent.UploadArticleListing( TheNGARecord );
  5082. end;
  5083.  
  5084. procedure TCCINetCCForm.EntireQueue1Click(Sender: TObject);
  5085. var TheNGRecord : PNewsGroupRecord;
  5086. begin
  5087.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5088.   TheNNTPComponent.UploadAllArticleListings( TheNGRecord );
  5089. end;
  5090.  
  5091. procedure TCCINetCCForm.AllReadArticles1Click(Sender: TObject);
  5092. var TheNGRecord : PNewsGroupRecord;
  5093. begin
  5094.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5095.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5096.   SetupNewsGroupListboxes;
  5097. end;
  5098.  
  5099. procedure TCCINetCCForm.AllMarkedArticles1Click(Sender: TObject);
  5100. var TheNGRecord : PNewsGroupRecord;
  5101.     TheNGARecord : PNewsGroupArticleRecord;
  5102.     WorkingList : TList;
  5103.     Counter_1 : Integer;
  5104. begin
  5105.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5106.   WorkingList := TList( TheNGRecord^.GLTag );
  5107.   for Counter_1 := 0 to ListBox2.Items.Count - 1 do
  5108.   begin
  5109.     if ListBox2.Selected[ Counter_1 ] then
  5110.     begin
  5111.       TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_1 ] );
  5112.       TheNGARecord^.NGARead := true;
  5113.     end;
  5114.   end;
  5115.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5116.   SetupNewsGroupListboxes;
  5117. end;
  5118.  
  5119. procedure TCCINetCCForm.AllAvailableArticles1Click(Sender: TObject);
  5120. var TheNGRecord : PNewsGroupRecord;
  5121.     TheNGARecord : PNewsGroupArticleRecord;
  5122.     WorkingList : TList;
  5123.     Counter_1  : Integer;
  5124. begin
  5125.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5126.   WorkingList := TList( TheNGRecord^.GLTag );
  5127.   for Counter_1 := 0 to ListBox2.Items.Count - 1 do
  5128.   begin
  5129.     TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_1 ] );
  5130.     TheNGARecord^.NGARead := true;
  5131.   end;
  5132.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5133.   SetupNewsGroupListboxes;
  5134. end;
  5135.  
  5136. procedure TCCINetCCForm.DownloadActiveNewsgroups1Click(Sender: TObject);
  5137. begin
  5138.   if MessageDlg( 'This will take considerable time. Proceed?',mtConfirmation,
  5139.    mbYesNoCancel,0) = mrYes then
  5140.   begin
  5141.     Memo1.Clear;
  5142.     TheNNTPComponent.GetListofAvailableNewsGroups;
  5143.   end;
  5144. end;
  5145.  
  5146. procedure TCCINetCCForm.UUEncode1Click(Sender: TObject);
  5147. begin
  5148.   OpenDialog1.Filename := '*.*';
  5149.   OpenDialog1.Title := 'Select File to UUENCODE';
  5150.   if OpenDialog1.Execute then
  5151.   begin
  5152.     TheUUObject.SetInputFileName( OpenDialog1.FileName );
  5153.     TheUUObject.EncodeCurrentInputs;
  5154.   end;
  5155. end;
  5156.  
  5157. procedure TCCINetCCForm.Load1Click(Sender: TObject);
  5158. var Memo2 : TMemo;
  5159.     Counter_1 : Integer;
  5160. begin
  5161.   OpenDialog1.Filename := '*.txt';
  5162.   OpenDialog1.Title := 'Select File to load into Memo';
  5163.   if OpenDialog1.Execute then
  5164.   begin
  5165.     Memo2 := TMemo.Create( Self );
  5166.     Memo2.Parent := Self;
  5167.     Memo2.Visible := false;
  5168.     Memo2.Width := Memo1.Width;
  5169.     Memo2.Height := Memo1.Height;
  5170.     Memo2.Lines.LoadFromFile( OpenDialog1.FileName );
  5171.     for Counter_1 := 0 to Memo2.Lines.Count - 1 do
  5172.      Memo1.Lines.Add( Memo2.Lines[ Counter_1 ] );
  5173.     Memo2.Free;
  5174.   end;
  5175. end;
  5176.  
  5177. procedure TCCINetCCForm.Save1Click(Sender: TObject);
  5178. begin
  5179.   SaveDialog1.Filename := '*.txt';
  5180.   SaveDialog1.Title := 'Select File to Save Memo to';
  5181.   if OpenDialog1.Execute then
  5182.   begin
  5183.     Memo1.Lines.SaveToFile( SaveDialog1.FileName );
  5184.   end;
  5185. end;
  5186.  
  5187. procedure TCCINetCCForm.EMail1Click(Sender: TObject);
  5188. begin
  5189.   if TheFTPComponent.Connection_Established then
  5190.   begin
  5191.     MessageDlg( 'Must disconnect from current FTP session first!',
  5192.      mtError,[mbOK],0);
  5193.     exit;
  5194.   end;
  5195.   if TheNNTPComponent.Connection_Established then
  5196.   begin
  5197.     MessageDlg( 'Must disconnect from current NNTP session first!',
  5198.      mtError,[mbOK],0);
  5199.     exit;
  5200.   end;
  5201.   { Show The POP3SMTP servers display }
  5202.   ListBox1.Clear;
  5203.   ListBox2.Clear;
  5204.   SetupEMailServerStatus;
  5205.   EnablePOP3SMTPMenus;
  5206.   SetupEMailServersInfoDisplay;
  5207. end;
  5208.  
  5209. procedure TCCINetCCForm.CheckMail1Click(Sender: TObject);
  5210. begin
  5211.   WhichServer := ComboBox1.ItemIndex + 1;
  5212.   if not EMailLoaded then
  5213.   begin
  5214.     LoadEMailMailBoxFile( WhichServer );
  5215.     LoadEMailCorrespondentsFile;
  5216.     EmailLoaded := true;
  5217.   end;
  5218.   DoPOP3Connection( TheEMailServerList.Items[ WhichServer - 1 ] );
  5219.   ThePOP3SMTPComponent.DownloadAllMessageListings(
  5220.    PEMailMailBoxRecord( TheEMailMailboxList.Items[ 0 ] ));
  5221.   ThePOP3SMTPComponent.POP3Disconnect;
  5222.   SetupEMailListBoxes;
  5223. end;
  5224.  
  5225. procedure TCCINetCCForm.MailServers1Click(Sender: TObject);
  5226. begin
  5227.   SetupEmailServersInfoDisplay;
  5228.   CCICInfoDlg.ShowModal;
  5229. end;
  5230.  
  5231. procedure TCCINetCCForm.Mailboxes1Click(Sender: TObject);
  5232. begin
  5233.   SetupEmailMailboxInfoDisplay;
  5234.   CCICInfoDlg.ShowModal;
  5235.   SetupEMailListBoxes;
  5236. end;
  5237.  
  5238. procedure TCCINetCCForm.Correspondents1Click(Sender: TObject);
  5239. begin
  5240.   SetupEmailCorrespondentsInfoDisplay;
  5241.   CCICInfoDlg.ShowModal;
  5242. end;
  5243.  
  5244. procedure TCCINetCCForm.EMail3Click(Sender: TObject);
  5245. begin
  5246.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 0;
  5247.   CCICPrefsDlg.Tag := 6;
  5248.   CCICPrefsDlg.ShowModal;
  5249. end;
  5250.  
  5251. procedure TCCINetCCForm.Paths1Click(Sender: TObject);
  5252. begin
  5253.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 3;
  5254.   CCICPrefsDlg.Tag := 3;
  5255.   CCICPrefsDlg.ShowModal;
  5256. end;
  5257.  
  5258. procedure TCCINetCCForm.ExitEMailRequired1Click(Sender: TObject);
  5259. begin
  5260.   if not ThePOP3SMTPComponent.Connection_Established then exit;
  5261.   DoPOP3SMTPDisconnect;
  5262.   SaveEMailMailBoxFile( WhichServer );
  5263.   SaveEMailCorrespondentsFile;
  5264.   DisablePOP3SMTPMenus;
  5265.   EMailLoaded := false;
  5266. end;
  5267.  
  5268. procedure TCCINetCCForm.TrashMarkedMessages1Click(Sender: TObject);
  5269. begin
  5270.   ThePOP3SMTPComponent.TrashAllMarkedMessages( ListBox2 ,
  5271.    PEMailMailboxRecord( TheEMailMailBoxList.Items[ ListBox1.Itemindex ] ));
  5272.   TheMBMessagesList := TList( PEMailMailboxRecord(
  5273.    TheEMailMailBoxList.Items[ ListBox1.Itemindex ] )^.MBLTag );
  5274.   PopulateLB2WithMessageHeaders;
  5275. end;
  5276.  
  5277. procedure TCCINetCCForm.EmptyTrash1Click(Sender: TObject);
  5278. var Counter_1 : Integer;
  5279. begin
  5280.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  5281.   begin
  5282.     ThePOP3SMTPComponent.PurgeTrashedMessageListings(
  5283.      PEMailMailBoxRecord( TheEMailMailboxList.Items[ Counter_1 ] ));
  5284.   end;
  5285.   TheMBMessagesList := TList( PEMailMailboxRecord(
  5286.    TheEMailMailBoxList.Items[ 0 ] )^.MBLTag );
  5287.   SetupEmailListboxes;
  5288. end;
  5289.  
  5290. procedure TCCINetCCForm.MIMEDecode1Click(Sender: TObject);
  5291. var Counter_1    : Integer;
  5292.     TheEMMRecord : PEmailMessageRecord;
  5293. begin
  5294.   for Counter_1 := 0 to ListBox2.Items.Count - 1 do
  5295.   begin
  5296.     if ListBox2.Selected[ Counter_1 ] then
  5297.     begin
  5298.       TheEMMRecord :=
  5299.        PEMailMessageRecord( TheMBMessagesList.Items[ Counter_1 ] );
  5300.       TheMIMEObject.TheInputFileName := MailPath + '\' +
  5301.        TheEMMRecord^.MRFileName;
  5302.       TheMIMEObject.DecodeMIMEFile;
  5303.     end;
  5304.   end;
  5305. end;
  5306.  
  5307. procedure TCCINetCCForm.Cut1Click(Sender: TObject);
  5308. begin
  5309.   Memo1.CutToClipboard;
  5310. end;
  5311.  
  5312. procedure TCCINetCCForm.Copy1Click(Sender: TObject);
  5313. begin
  5314.   Memo1.CopyToClipboard;
  5315. end;
  5316.  
  5317. procedure TCCINetCCForm.CopytoFile1Click(Sender: TObject);
  5318. var TempMemo : TMemo;
  5319. begin
  5320.   TempMemo := TMemo.Create( self );
  5321.   TempMemo.parent := self;
  5322.   Tempmemo.Visible := false;
  5323.   TempMemo.Width := Memo1.Width;
  5324.   TempMemo.Height := Memo1.Height;
  5325.   Memo1.CopyToClipboard;
  5326.   TempMemo.PasteFromClipboard;
  5327.   SaveDialog1.Filename := '*.TXT';
  5328.   SaveDialog1.Title := 'Select File to Save To';
  5329.   if SaveDialog1.Execute then TempMemo.Lines.SaveToFile( SaveDialog1.Filename );
  5330.   TempMemo.Free;
  5331. end;
  5332.  
  5333. procedure TCCINetCCForm.Paste1Click(Sender: TObject);
  5334. begin
  5335.   Memo1.PasteFromClipboard;
  5336. end;
  5337.  
  5338. procedure TCCINetCCForm.PastefromFile1Click(Sender: TObject);
  5339. var TempMemo : TMemo;
  5340. begin
  5341.   TempMemo := TMemo.Create( self );
  5342.   TempMemo.parent := self;
  5343.   Tempmemo.Visible := false;
  5344.   TempMemo.Width := Memo1.Width;
  5345.   TempMemo.Height := Memo1.Height;
  5346.   OpenDialog1.Filename := '*.*';
  5347.   OpenDialog1.Title := 'Select File to Paste From';
  5348.   if OpenDialog1.Execute then TempMemo.Lines.LoadFromFile( OpenDialog1.Filename );
  5349.   TempMemo.SelectAll;
  5350.   TempMemo.CopyToClipboard;
  5351.   Memo1.PasteFromClipboard;
  5352.   TempMemo.Free;
  5353. end;
  5354.  
  5355. procedure TCCINetCCForm.SpeedButton5Click(Sender: TObject);
  5356. begin
  5357.   case Tag of
  5358.     5 : AllMarkedArticles1Click( Self );
  5359.     6 : TrashMarkedMessages1Click( self ); 
  5360.   end;
  5361. end;
  5362.  
  5363. procedure TCCINetCCForm.SpeedButton3Click(Sender: TObject);
  5364. begin
  5365.   case Tag of
  5366.     6 : MIMEDecode1Click( self );
  5367.   end;
  5368. end;
  5369.  
  5370. procedure TCCINetCCForm.SpeedButton1Click(Sender: TObject);
  5371. begin
  5372.   case Tag of
  5373.     5 : begin
  5374.           if ListBox2.Items.Count = 0 then exit;
  5375.           Listbox2.multiselect := false;
  5376.           If ListBox2.ItemIndex = -1 then ListBox2.ItemIndex := 0;
  5377.           ListBox2.ItemIndex := Listbox2.ItemIndex - 1;
  5378.           if ListBox2.Itemindex < 0 then
  5379.            Listbox2.Itemindex := ListBox2.Items.Count - 1;
  5380.           ListBox2DblClick( Self );
  5381.           ListBox2.Multiselect := true;
  5382.           ListBox2.SetFocus;
  5383.         end;
  5384.   end;
  5385. end;
  5386.  
  5387. procedure TCCINetCCForm.SpeedButton2Click(Sender: TObject);
  5388. begin
  5389.   case Tag of
  5390.     5 : begin
  5391.           if ListBox2.Items.Count = 0 then exit;
  5392.           ListBox2.MultiSelect := false;
  5393.           If ListBox2.ItemIndex = -1 then ListBox2.ItemIndex := 0;
  5394.           ListBox2.ItemIndex := Listbox2.ItemIndex + 1;
  5395.           if ListBox2.Itemindex > ListBox2.Items.Count - 1 then
  5396.            Listbox2.Itemindex := 0;
  5397.           ListBox2DblClick( Self );
  5398.           ListBox2.MultiSelect := true;
  5399.           ListBox2.SetFocus;
  5400.         end;
  5401.   end;
  5402. end;
  5403.  
  5404. procedure TCCINetCCForm.ListBox2Click(Sender: TObject);
  5405. var TheWorkingList : TList;
  5406.     TheNGARecord : PNewsGroupArticleRecord;
  5407.     TheNGRecord : PNewsGroupRecord;
  5408.     TheWorkingName : String;
  5409. begin
  5410.   if ListBox2.Tag = 9 then
  5411.   begin
  5412.     TheNGRecord :=
  5413.      PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5414.     TheWorkingList := TList( TheNGRecord^.GLTag );
  5415.     TheNGARecord := PNewsGroupArticleRecord(
  5416.      TheWorkingList.Items[ ListBox2.ItemIndex ] );
  5417.     TheWorkingName := NewsPath + '\' + TheNGARecord^.NGAArtFileName;
  5418.     TheUUDecodeList.Add( TheWorkingName );
  5419.     exit;
  5420.   end;
  5421.   case Tag of
  5422.     5 : begin
  5423.           If ListBox2.Items.Count = 0 then exit;
  5424.           ComboBox1.Text := ListBox2.Items[ ListBox2.ItemIndex ];
  5425.         end;
  5426.   end;
  5427. end;
  5428.  
  5429. procedure TCCINetCCForm.AbortNewsgroupDownload1Click(Sender: TObject);
  5430. begin
  5431.   GlobalAbortedFlag := true;
  5432. end;
  5433.  
  5434. procedure TCCINetCCForm.Marked1Click(Sender: TObject);
  5435. var Counter_1,
  5436.     Counter_2   : Integer;
  5437.     TheNGRecord : PNewsGroupRecord;
  5438.     TheNGARecord : PNewsGroupArticleRecord;
  5439.     WorkingList : TList;
  5440. begin
  5441.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  5442.   begin
  5443.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5444.     if (( TheNGRecord^.GSubscribed ) and ( ListBox1.Selected[ Counter_1 ] )) then
  5445.     begin
  5446.       WorkingList := TList( TheNGRecord^.GLTag );
  5447.       for Counter_2 := 0 to ListBox2.Items.Count - 1 do
  5448.       begin
  5449.         TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  5450.         TheNGARecord^.NGARead := true;
  5451.       end;
  5452.       TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5453.       TheNGRecord^.GLowest := TheNGRecord^.GHighestAvailable;
  5454.       TheNGRecord^.GHighest := TheNGRecord.GLowest;
  5455.       TheNGRecord^.GTotalNew := 0;
  5456.       TheNGRecord^.GTotalArticles := 0;
  5457.     end;
  5458.   end;
  5459.   SetupNewsGroupListboxes;
  5460. end;
  5461.  
  5462. procedure TCCINetCCForm.All1Click(Sender: TObject);
  5463. var Counter_1,
  5464.     Counter_2   : Integer;
  5465.     TheNGRecord : PNewsGroupRecord;
  5466.     TheNGARecord : PNewsGroupArticleRecord;
  5467.     WorkingList : TList;
  5468. begin
  5469.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  5470.   begin
  5471.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5472.     if TheNGRecord^.GSubscribed then
  5473.     begin
  5474.       WorkingList := TList( TheNGRecord^.GLTag );
  5475.       for Counter_2 := 0 to ListBox2.Items.Count - 1 do
  5476.       begin
  5477.         TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  5478.         TheNGARecord^.NGARead := true;
  5479.       end;
  5480.       TheNGRecord^.GLowest := TheNGRecord^.GHighestAvailable;
  5481.       TheNGRecord^.GHighest := TheNGRecord.GLowest;
  5482.       TheNGRecord^.GTotalNew := 0;
  5483.       TheNGRecord^.GTotalArticles := 0;
  5484.       TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5485.     end;
  5486.   end;
  5487.   SetupNewsGroupListboxes;
  5488. end;
  5489.  
  5490. procedure TCCINetCCForm.File1Click(Sender: TObject);
  5491. begin
  5492.   OpenDialog1.Filename := '*.uue';
  5493.   OpenDialog1.Filter := 'UUEncode Files|*.uue|All Files *.*';
  5494.   OpenDialog1.Title := 'Select File To Decode';
  5495.   if OpenDialog1.Execute then
  5496.   begin
  5497.     TheUUObject.SetInputFileName( OpenDialog1.FileName );
  5498.     TheUUObject.SetMultifileVector( CMV_SINGLE );
  5499.     TheUUObject.Decode;
  5500.   end;
  5501. end;
  5502.  
  5503. procedure TCCINetCCForm.SelectedArticle1Click(Sender: TObject);
  5504. var TheWorkingList : TList;
  5505.     TheNGARecord : PNewsGroupArticleRecord;
  5506.     TheNGRecord : PNewsGroupRecord;
  5507.     TheWorkingName : String;
  5508. begin
  5509.   TheNGRecord :=
  5510.    PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5511.   TheWorkingList := TList( TheNGRecord^.GLTag );
  5512.   TheNGARecord := PNewsGroupArticleRecord(
  5513.    TheWorkingList.Items[ ListBox2.ItemIndex ] );
  5514.   TheWorkingName := NewsPath + '\' + TheNGARecord^.NGAArtFileName;
  5515.   TheUUObject.SetInputFileName( TheWorkingName );
  5516.   TheUUObject.SetMultifileVector( CMV_SINGLE );
  5517.   TheUUObject.Decode;
  5518. end;
  5519.  
  5520. procedure TCCINetCCForm.SelectMultipleArticles1Click(Sender: TObject);
  5521. begin
  5522.   { Set tag so that listbox knows to keep track of hits}
  5523.   ListBox2.Tag := 9;
  5524.   ListBox2.MultiSelect := false;
  5525.   TheUUDecodeList := TStringList.Create;
  5526. end;
  5527.  
  5528. procedure TCCINetCCForm.DecodeSelections1Click(Sender: TObject);
  5529. begin
  5530.   ListBox2.Tag := 5;
  5531.   ListBox2.MultiSelect := True;
  5532.   if TheUUDecodeList.Count = 0 then exit;
  5533.   TheUUObject.SetMultipleFilesList( TheUUDecodeList );
  5534.   TheUUObject.SetMultifileVector( CMV_MULTI );
  5535.   TheUUObject.Decode;
  5536.   TheUUDecodeList.Free;
  5537. end;
  5538.  
  5539. procedure TCCINetCCForm.SpeedButton4Click(Sender: TObject);
  5540. begin
  5541.   case Tag of
  5542.     5 : begin
  5543.           SelectedArticle1Click( Self );
  5544.         end;
  5545.   end;
  5546. end;
  5547.  
  5548. end.
  5549.  
  5550.